
I have a few different websites/blogs and some of them are related to one another either by content, purpose or similar audience. Specifically, my new website wpZipper.com has been receiving a fair amount of traffic lately and I wanted an easy way to cross-promote this blog, wpstar, and pull some traffic this way. My simple fix involves a slightly customized script using the SimplePie feed parser.
This is a fairly quick and dirty way to do this, but it works beautifully. Here is how it works on wpZipper.
First, grab a copy of SimplePie (just click that big ol’ blue button–this isn’t a tutorial on how to do this in WordPress– I’ll do a write up on that later). Follow the directions and upload the simplepie.inc file to an appropriate folder on your server (I put mine in an “inc” folder).
Next, create the function to check the feed of the blog you want to link to. In this case, I want to check if there has been a post in the past 24 hours at wpstar.com. If there is, I want to display a link to it. I tend to put all my functions inside the same PHP file and then include that file on all my pages that require functions. Here is what the code looks like:
function check_wpstar(){
include_once('inc/simplepie.inc');
$feed = new SimplePie('http://feeds.feedburner.com/wpstar');
// Create a new array to hold data in
$new = array();
// Loop through all of the items in the feed
for ($x=0; $x < $feed->get_item_quantity(); $x++) {
// Make sure that we have a handle for the current item.
$item = $feed->get_item($x);
// Calculate 24 hours ago
$yesterday = time() - (24*60*60);
// Compare the timestamp of the feed item with 24 hours ago.
if ($item->get_date('U') > $yesterday) {
// If the item was posted within the last 24 hours, display a message.
echo "pssst! There's a new post today over at wpstar!";
}
}
}
This code was originally grabbed from a forum post at SimplePie and customized. As you can see, the code loads the feed from wpstar.com and compares the timestamp of the most recent post against a time constraint (in this case, 24 hours). If the most recent post has occurred within the past 24 hours, then a message will be displayed alerting website visitors. If not, nothing is displayed.
Finally, you’ll want to call this function somewhere on your page (where you want the message to be displayed). The code you would use would be like this:
<?php check_wpstar(); ?>
That’s it. Check this out in action over at wpZipper.com. The message appears at the very top of the page if a new post has been made on wpstar within the past 24 hours.
Projects
LifeStream
- August 26th
- 12:51 pm New blog entry 'I Should Be Depressed' - http://tinyurl.com/6xeyj6 (via Twitter)
- 9:56 am @bradjward So is yelling "hey you!" if they look = consent ;p (via Twitter)
- 8:48 am @smyle4_me NOOOOOOOOOOO!! (via Twitter)
- 3:45 am I Should Be Depressed (via Blog)
- August 25th
- 10:24 pm

- 2:15 pm Just registered for Connections '08: ExactTarget User Conference! :D (via Twitter)
- August 24th
- 7:46 am @joshgillespie I could probably do it (though, no one can ever really replace @hoosierplew). Let me check and see what my plans are Sat. (via Twitter)
- August 23rd
- 9:52 pm @apsonsi Oops! Really sorry! A little preoccupied today. Yes, will def add you to the list. We're probably going to need help next year! (via Twitter)
- 10:03 am @apsonsi Autograph blog? interesting. like to hear more. As for Blog Indiana, you're a week late :( But, we'll def need volunteers for 2009! (via Twitter)
- August 22nd
- 7:33 pm

- 7:12 pm Wow, that bumper sticker story is really fueling Obama Bayh speculation... suddenly 288 active visitors on ObamaBayh.com right now. (via Twitter)
- 7:07 pm @kyleplacy @edeckers @ScottWilder ObamaBayh.com is mine ;) The CNN story was about all the domains people have for the VP prospects. (via Twitter)
- 6:56 pm sweet! my name just mentioned on cnn! autograph $10! (via Twitter)
- 5:48 pm Being stalked by Abbi Tatton ;) (via Twitter)
- 2:01 pm

- 10:55 am @hoosierplew No go, I think @mooshinindy only responds to piratespeak now. (via Twitter)
- 10:34 am Fav quote from BlogIndiana was from @hoosierplew to @mooshinindy when leaving the networking event: 'I'm going to follow you...' (creepy!) (via Twitter)
- 10:23 am @smyle4_me lol... you are an official twitter user once you see the fail whale! (via Twitter)
- 9:43 am @kaj Sure! What kind of job are you looking for? (via Twitter)
- 9:36 am I'm now 2 for 2 this year on helping friends find jobs! Too bad it doesn't pay anything :) (via Twitter)
- August 21st
- 7:22 pm bah.. hate that Twhirl uses IE's internet connection (via Twitter)
- 7:18 pm @ First Blog Indiana "OMG WE HAD A CONFERENCE" meeting (via Twitter)
- 7:18 pm @pastaqueen Ice cream in the mail? fail. (via Twitter)
- 4:24 pm @nickilaycoax I tweet because I can't hear any of you from where you're sitting... (via Twitter)
- 3:49 pm drobo is happy. (via Twitter)
- 9:14 am Anyone know of local facilities that rent use of their computer labs for training purposes? (via Twitter)
- August 20th
- 11:02 pm oh hai HD raining olympics channel... (via Twitter)
- 7:16 pm quick stop @ the bean cup on SS (via Twitter)
- 7:04 pm @bnpositive that's because they went to GenCon instead! (j/k) (via Twitter)
- 4:19 pm @IndianaJeff @hoosierplew http://is.gd/1Mlk (via Twitter)
- 12:03 pm New blog entry 'Blog Indiana 2008 Wrap-up' - http://tinyurl.com/5ghqwm (via Twitter)
- 12:03 pm Blog Indiana 2008 Wrap-up (via Blog)
- 10:00 am A sign you may drink too much coffee... you use a small amount of today's coffee to wash out your mug. (via Twitter)
- August 19th
- 9:54 pm Conference Wiki is Live (via Blog)
- 8:14 am I see the oddest things on 465 every morning. today? a large picnic table on the shoulder that was clearly run into at high speed. (via Twitter)
- August 18th
- 1:02 am BlogIndiana 2008 in the books, time to talk BlogIndiana 2009 (via Blog)
- August 17th
- 11:13 pm

- 6:34 pm Indiana (and regional) bloggers rock! thanks everyone for a great conference! i loved meeting so many of you! (via Twitter)
- 2:08 pm @blogindiana has lots of sandwiches left... eat up! (via Twitter)
- 2:07 pm @blogindiana the FailWhale says: ya bloggers behave! Arrrrrrrrghh (splash) (via Twitter)

One Response
You might also take a look at WPGet:
http://peter.upfold.org.uk/projects/wpget
which will directly pull posts from the database. That approach is a bit more flexible than parsing RSS in some ways, and there’s also a super-easy setup wizard.
Leave a reply