Including Blog Posts Within Area Of Another Web Site

Discussion corner for Developers of Serendipity.
Post Reply
mtroutman
Regular
Posts: 6
Joined: Thu Jan 07, 2010 5:24 pm

Including Blog Posts Within Area Of Another Web Site

Post by mtroutman »

Hi! I hope someone will be kind enough to assist me. I have developed a site for my kids' school district. It can be viewed here: http://www.fairfieldcityschools.com/2010

On the right-hand side of the site, there is a "panel" with informational content. The district has requested that I create a blog for the superintendent so she can "toot her horn." (UGH) :roll:

I've set up the Serendipity blog and it's working great! It can be viewed here: http://www.fairfieldcityschools.com/Blog

I now need to somehow display the superintendent's posts within this small panel on the right-hand side of the main site. The right-hand panel is there by way of SSI and the content file is a .SHTML...

I've browsed through this forum looking for a way to do it without bothering anyone and have tried a couple of different things including converting from .SHTML to .PHP but it's not working.

I would be forever in someone's debt if they could help me. I'm really under-the-gun on this one. Thank you so much! :oops:

Marianne Troutman
info(at)studio74designs(dot)com
Stumped Web Designer Begging For Help From ANYONE Smarter Than She (That would be EVERYONE)...
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Including Blog Posts Within Area Of Another Web Site

Post by garvinhicking »

Hi!

I don'T really unterstand this SSI/content file stuff. How does the code look, what exactly did you try?

You either need to write up a PHP file to include the s9y api as a wrapper, and use methods outlined here:http://www.s9y.org/78.html#A7

Or you use a plugin called serendipity_event_backend (available through spartacus) that allows you to call a URL of your blog so that you can place it as a javascript in a foreign site; the files coming with the plugin should contain some basic DOcumentation/Example...

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mtroutman
Regular
Posts: 6
Joined: Thu Jan 07, 2010 5:24 pm

Re: Including Blog Posts Within Area Of Another Web Site

Post by mtroutman »

Hi! Thanks for responding. SSI / Includes, at least on the site I'm working on look something like this...

<!--#include virtual="/Directory/PageName.shtml" -->

The ".shtml" extension is necessary for this method to work.

The purpose of this is so that you can include content on multiple pages without having to edit each and every page individually. This comes in handy when a site contains litterally thousands of pages...

With that explained, I'm trying to include the content of the blog into a panel set up on the right side of the site's template. This would need to be set up in a file called, "RightPanelBlog.shtml"

The content of "RightPanelBlog.shtml" would contain the necessary code to have the blog posts appear. I checked all of this out on this site before posting this thread, tried to get it to work on my own before begging for help - all with no luck.

If the file needs to be a .php file, I can make that work for this purpose. I really just need to get this code to work. Here's the code(s) I've tried to use so far:
Embedding Serendipity in Something Else
This is not the recommended way to embed with Serendipity. Frankly, it's just a pain to get all the configuration correct. We highly recommend that you embed your "Something Else" into Serendipity, instead.

So, you're determined, eh? Well, then...

The Basics
Serendipity will not run correctly unless it is called from the proper directory. Since it is a PHP program, you'll also need to call it using the proper PHP syntax. Here's the very simplest case:

<?php
chdir("<serendipity_dir>");
require("index.php");
chdir("<original_dir>");
?>

The first line changes to the serendipity directory (substitute the correct directory for <serendipity_dir>, of course). The second actually runs Serendipity and prints everything out. The third switches back to your original directory (naturally, substitute <original_dir>).

You can also save the output to be used later, instead of printing it immediately. This is especially useful if you're embedding Serendipity into a PHP program. One way to save the output is like this:

<?php
ob_start();
chdir("<serendipity_dir>");
require("index.php");
chdir("<original_dir>");
$serendipity_contents = ob_get_contents();
ob_end_clean();
?>

The "ob" stands for "output buffer". This captures the previous stuff into a buffer, gets the contents of the buffer into $serendipity_contents, and then ends the capturing. Now you can just print $serendipity_contents anywhere you want the blog to show up.

Note that this can used as a "wrapper"; it's a little PHP file that calls Serendipity and stores the contents in a variable. For instance, if you saved it as "serendipity_wrapper.php" in any directory, you could then

require("<full_path>/serendipity_wrapper.php");

and you'd get a variable containing $serendipity_contents that you could use anywhere. Neat, eh?

It's more than just neat. If you get errors saying "Warning: Cannot modify header information - headers already sent", you'll need to use the wrapper. No output is allowed before calling Serendipity, so you'll have to call it first. If you want the Serendipity output anywhere other than at the top of the file, you'll need to store the output in a variable and use it later. Here's an example:

<?php
require("wrapper.php"); // stores S9Y in a variable
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
Your non-Serendipity content goes here.
<?php
echo $serendipity_contents; // Print the variable
?>
More non-Serendipity content here.
</body>
</html>

Just calling Serendipity in the middle of the HTML could have caused the "header already sent" error.

Changing Serendipity's Embedded Appearance
So, now you've got Serendipity embedded, and you'd like to change its appearance. By default, Serendipity attempts to provide its theme and sidebars.

Removing theming and header HTML
To remove the theming and header HTML, go to your admin page and change the configuration. Find the setting for "Is Serendipity embedded?" and change it to "Yes". Now Serendipity will output only its HTML; no stylesheet will be included, and no <HTML>, <HEAD>, or <BODY> tags.

Sidebars are easier, and a bit more obvious. Go to your admin page, choose "Configure Plugins", and set all the sidebar plugins to "Hidden". You could choose to remove them, too. Serendipity will no longer print sidebars.

Other appearance changes
Of course, you can also set variables in your wrapper that affect Serendipity before calling it. More on this as more people get time to update this document.

Known Issues
If you use compressed output buffering, you might get blank pages when embedding Serendipity. This is because multiple gzipped page buffers might not go well with each other. The solution to this is to turn off output compression in the Serendipity or PHP configuration.
Here's the address to the blog in question:
http://www.fairfieldcityschools.com/Blog

And here's the URL for the site in question, where the blog should appear (just the text entries) at the top of the right panel. There is just a link to the blog for now until I can make this work, but the pressure is on - they want me to roll out the new site on Friday -YIKES!

http://www.fairfieldcityschools.com/2010

Thanks in advance for the help!!! I don't see me ever volunteering to help with my kids' school district again, any time soon... LOL
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Including Blog Posts Within Area Of Another Web Site

Post by garvinhicking »

Hi!

Actually, SSI is a concurring method to PHP. You should use PHP to include Serendipity, like the way I outlined. PHP is needed for dynamic allocation, so you can use that to dynamically include content. SSI only includes static files, as far as I know.

Embedding goes into a similar direction, but the route inside the link of http://www.s9y.org/78.html#A7 is more matching. It does share code similarities, though.

However the serendipity_event_backend plugin should do what you find in a much more simpler way for you, if you only want some entries to be linked in there.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mtroutman
Regular
Posts: 6
Joined: Thu Jan 07, 2010 5:24 pm

Re: Including Blog Posts Within Area Of Another Web Site

Post by mtroutman »

First, let me say that you're an angel for responding to my posts. I hope that they help others in my situation...

When I'm setting this up, I create the 'wrapper.php' file and save it to a folder within the directory known as 'scripts.'

Next, I use SSI to include that file in the area of the site I want the blog posts to appear in.

After that, I make sure that the contents of the 'wrapper.php' file are pointing where they should. Here's the example...
<?php
ob_start();
chdir("<Blog_dir>");
require("index.php");
chdir("<Blog_dir>");
$serendipity_contents = ob_get_contents();
ob_end_clean();
?>
Is the code pointing in the right direction?

Should I also go into the blog management panel and set it to 'allow embedding' in order for all of this to work? If I do that, then if anyone views the blog outside of the embedding, they see the blog in it's simplest 'text form' without any of the formatting. Is this correct?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Including Blog Posts Within Area Of Another Web Site

Post by garvinhicking »

Hi!

Not really; the wrapper you are currently about to use includes the WHOLE blog. But you only want specific entries. Which is why you need to manually call the s9y API for serendipity_fetchEntries() etc.

However, as I pointed out earlier, using the backend plugin is the much better way for someone without PHP knowledge.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mtroutman
Regular
Posts: 6
Joined: Thu Jan 07, 2010 5:24 pm

Re: Including Blog Posts Within Area Of Another Web Site

Post by mtroutman »

Hi!

I tried using the method according to the link you provided. I think we're almost there. Below is a link to the 'test page' I'm using to get this thing working...

http://www.fairfieldcityschools.com/Blo ... lude.shtml

Here is the code I used in a file called, "RightPanelBlog.php"
<?php
// 1: Switch to the Serendipity path. We need to use chdir so that the s9y framework can use its relative calls.
chdir('/home/www/fairfieldcityschools.com/');

// 2: Start the Serendipity API
include 'serendipity_config.inc.php';

// 3: Start Smarty templating
serendipity_smarty_init();

// 4: Get the latest entries
$entries = serendipity_fetchEntries(null, true,1);

// 5: Put all the variables into Smarty
serendipity_printEntries($entries);

// 6: Get the template file
$tpl = serendipity_getTemplateFile('entries.tpl', 'serendipityPath');

// 7: Format and output the entries
$serendipity['smarty']->display($tpl);

// 8: Go back to where you came from
chdir('/home/www/fairfieldcityschools.com/');
?>
That code is called in from a file called, "RightContent.php" and here's the code on that page:
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td align="center" valign="top"><?php require_once('RightPanelBlog.php'); ?></td>
</tr>
</table>
Finally, the "RightContent.php" page is included using SSI in the right panel using the following code:
<!--#include virtual="/BlogContent.php" -->
which can be seen here:

http://www.fairfieldcityschools.com/Blo ... lude.shtml


I get an error message when viewing the page that says:
[an error occurred while processing this directive]
That's the closest I've come to getting this to work so I'm feeling good that I'm almost there. Any ideas on what I'm missing?

Thanks for your help!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Including Blog Posts Within Area Of Another Web Site

Post by garvinhicking »

Hi!

Probably this won't work with SSI. I don't know if SSI can parse PHP. I don't think so.

Please, please, please have a look at that plugin I mentioned. It is much more suitable for people without PHP knowledge.

:)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mtroutman
Regular
Posts: 6
Joined: Thu Jan 07, 2010 5:24 pm

Re: Including Blog Posts Within Area Of Another Web Site

Post by mtroutman »

Okay...

I've set up the "spartacus plug in" as you've suggested. It's still not working...

Here's what the README file tells me to do:
simply add a "<script src=[URL]></script>" to your external website
at exactly the place, where the entries should appear.

[URL] should be something like:
http://your.blog.com/plugin/[BACKEND_URL]?[OPTIONS]
Here's what I've configured where I want the blog entries to appear:
There's still nothing showing...

Here is the path to the installed plugin:

http://www.fairfieldcityschools.com/Blo ... t_backend/

I can't configure the options until I can even get this thing to show up. I'm sure this way of yours is easier but I think I've been working on this project so long that I just can't do anything 'easily' anymore. I'm positive I'm close to resolving this issue and I'm missing something very simple but I just can't figure out what it is.

What am I missing on this (besides enough intelligence to figure it out)?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Including Blog Posts Within Area Of Another Web Site

Post by garvinhicking »

Hi!

Once you installed and enabled the plugin from your s9y admin interface, you actually configure the BACKEND_URL. You could for example set it as "myentries". Then the URL needs to look like:

http://www.fairfieldcityschools.com/Blo ... /myentries

or if your blog allows URL rewriting it would be:

http://www.fairfieldcityschools.com/Blo ... /myentries

HTH,
GArvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mtroutman
Regular
Posts: 6
Joined: Thu Jan 07, 2010 5:24 pm

Re: Including Blog Posts Within Area Of Another Web Site

Post by mtroutman »

IT'S WORKING!!! IT'S WORKING!!!

You are so great to have put up with me for the past two weeks and help me out. Hopefully, this thread will provide others with the help they need so you don't have any other crazy people like me bothering you!

You're awesome! You rock! Thank you! Thank you! Thank you!

Warmest regards,

Marianne Troutman
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Including Blog Posts Within Area Of Another Web Site

Post by garvinhicking »

Hi!

Hey, that's great - what a relief! :-) :-)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply