
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
- March 14th
- 6:59 pm I am in free t-shirt heaven. #sxsw
- 12:32 pm @refreshindy I'm in.
- 4:48 am @LolaMcIntyre I co-founded #blogindiana with @hoosierplew #INDIANA
- 12:44 am RT @JasonFalls: As you wander tonight #sxsw stop by Little Woodrows (500 block of 6th) for @chilliefalls's famous funnel cakes.
- March 13th
- 10:39 pm @hunckler great! Lots of ppl but not packed.
- 10:18 pm Just met Daniel from the SXSX Secret Service. #sxsw #sxsbw
- 7:24 pm @Efriedland What?! No way, there was a huge line and they kicked the previous session out to make way. That sucks. Inglorious basterd! #sxsw
- 6:25 pm @hunckler That was the How to create a viral video session.
- 5:36 pm Make your videos unexpected. Example: Cookie Monster vs. Rammstein http://bit.ly/7X0XdV #sxsw #viralvideos
- 5:28 pm What I'm doing and where I'm sitting for #SXSW http://sitby.us/noahwesley
- 5:21 pm For my tweeps not at #SXSW but who are interested, check this out: http://sessiontweets.com
- 5:15 pm "The key to a good viral video is boobies & kittens." #sxsw #viralvideo
- 5:03 pm 4 rows back from the cameras on the left. 2 seats next to me open. http://sitby.us/0496/
- 5:01 pm RT @pateast: Hanapin is recruiting the best and brightest! Have SEO or PPC experience? Marketing or account management? We want you! http://bit.ly/ca7kCp
- 3:59 am Oh. My. Seafood. http://tweetphoto.com/14192310
- 3:04 am @smyle4_me firemen something )hic(
- 2:55 am @jamespaden you gotta try the local beer or @chris_c_lucas will lick ur face!
- 2:30 am @jamespaden beeeeeeeeEeeeeeeeer!
- March 12th
- 11:19 pm RT @adeolonoh: Rumors of my arrest are completely untrue. (But ironically, I did get a speeding ticket this a.m.)
- 11:18 pm SXSW fire alarm. Whole building emptying. Fail.
- 10:34 pm I'm at SXSWI Registration w/ 72 others. http://4sq.com/cVWx7L
- 7:56 pm Woo hoo! http://tweetphoto.com/14142281
- 7:53 pm Hoax.
- 6:44 pm @chuckgose what?? They didn't list that when I asked what they had!
- 6:41 pm @chuckgose I only got it cause the plane is full. :)
- 6:31 pm I am in first class but the seat behind me has a baby that just unloaded all his hopes and dreams into his diaper. #sxsw
- 2:18 pm @JasonFalls 9 to 9 today #sxswi
- 2:17 pm RT @jeremyawilliams: Check out West Baden Springs Hotel on "Big, Bigger, Biggest" on Science Channel tom (3/13) at 10PM http://ow.ly/1i3rS
- 2:12 pm RT @BlogIndiana: In just 3 days, more than 500 votes have been cast for #BIN2010 sessions! Have you voted? http://sessions.blogindiana.com/
- 2:10 pm RT @mooshinindy: Canada, Keep your darn geese in your own country. -America
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
WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.