
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
Stuff to click
LifeStream
- November 26th
- 12:07 pm @bnpositive Ha, yes, a compliment. I'm at the day job working on an actual fun project for a sales convention (read: pictures of beaches) (via Twitter)
- 11:57 am @bnpositive I think it's mostly due to your very accurate twitter avatar. It just makes you want to click "follow." (via Twitter)
- November 25th
- 10:26 pm @Phaedrus Wouldn't dream of it. I'm gonna miss this show, always makes me tense watching it. (via Twitter)
- 10:01 pm I can't even spell SHIELD I'm so excited! (via Twitter)
- 10:00 pm Freakin' THE SHEILD FINALE is on!!! Pause life! Pause life! (via Twitter)
- 7:03 pm Any of my fellow tweeps members of ASmallWorld.net? (via Twitter)
- 11:42 am RT @pateast We're giving away 2 tickets to Indy Startup Weekend. By 5 pm Wed, @me why we should choose you! http://zi.ma/dab9c2 (via Twitter)
- November 24th
- 10:35 pm

- 6:24 pm #magpie Corduroy is a super web-based billing system - http://corduroysite.com (via Twitter)
- 1:48 pm

- 10:18 am @indystartup Submit & vote on pre-weekend ideas for the upcoming Indianapolis Startup Weekend: http://is.gd/8Npj (via Twitter)
- November 23rd
- 7:50 pm

- November 21st
- 4:43 pm @douglaskarr what tweet-to-ad ration did you set for yourself? (via Twitter)
- 4:32 pm @bnpositive Yeah, but Google Apps is one of the few Google products with an upgrade path that leads to a pay-for service. (via Twitter)
- 2:07 pm Live TweetFeed of Hubspot webinar about Facebook #hubspot http://snurl.com/6907l (via Twitter)
- 2:03 pm Thank you, Twitter, for telling me about a webinar today that is relevant to my interests :D (via Twitter)
- November 19th
- 9:18 am I love it when one of the many IT dept. 'teams' tells me something isn't their job, that it's another team's. Are we living in caves? (via Twitter)
- November 17th
- 1:38 pm Am I the only one that sees the conflict with distributing 100,000 printed copies of a "green businesses" phonebook? http://snurl.com/5pyeg (via Twitter)
- November 12th
- 9:31 am Has anyone used or heard good/bad things about WorkEtc.com? (via Twitter)
- November 11th
- 4:00 pm After yesterday's 24 hr downtime of one of my employer's websites, I've now prominently displayed the Fail Whale in my cube in quiet protest (via Twitter)
- November 8th
- 4:41 pm

- 12:29 am watching the best movie ever with @hoosierplew: Army of Darkness (via Twitter)
- November 7th
- 6:07 pm

- 4:57 pm @bnpositive Oh, and we've changed your kid's grade from an A to a B- so the other kids don't feel as bad about their C on the spelling test. (via Twitter)
- 4:56 pm @bnpositive That is utterly stupid. Right, not everybody celebrates Christmas... but YOU do (it's HIS card!) (via Twitter)
- November 5th
- 1:58 pm I continue to be famous ;) Pics I uploaded to CNN from Tue got me mentioned towards the bottom of this CNN article: http://snurl.com/55b20 (via Twitter)
- 1:06 pm http://i33.tinypic.com/zx6yi8.jpg (via Twitter)
- November 4th
- 11:03 pm @Hockeyskates as long as I can pick. Last thing I want is to be flipping channels and suddenly Wolf Blitzer is standing in my living room. (via Twitter)
- 11:00 pm CNN projects Obama wins (via Twitter)
- 10:02 pm Wolf Blitzer just told us that the red states are for McCain and the blue states are for Obama... (via Twitter)
- 9:44 pm CNN just said they can't see how McCain will win, but please keep voting. Does the news learn nothing? (via Twitter)
- 6:26 pm CNN bustin out the futuristic 3D graphics (via Twitter)
- 5:12 pm Polls close in 49 minutes! Start drinkin' everybody!! (via Twitter)
- 3:50 pm http://getyourassoutofthehouseandvote.com (via Twitter)
- 3:35 pm Have you seen the stock market today? We should vote every day! (via Twitter)
- 9:20 am @TwitHeads Don't mess with Texas! (via Twitter)
- 8:00 am How do I always manage to screw up links... here it is: http://snurl.com/52ru5 (via Twitter)
- 7:59 am Pictures from my morning voting experience: http://snurl.com/52ru (via Twitter)
- 7:49 am

- 7:05 am track hoosierplew (via Twitter)
- 6:37 am Just voted! Only waited in line for 45 minutes (10 was before poll opened) (via Twitter)
- 6:06 am waiting in line to vote... (via Twitter)
- November 3rd
- 3:10 pm Trent Reznor just urged me to vote. (via Twitter)
- 2:13 pm @mrnoobie Free star-shaped donut from Krispy Kreme for voting, as well. God Bless America ;) (via Twitter)
- 2:06 pm @mrnoobie If you vote, Starbucks buys your coffee: http://is.gd/5w9E (via Twitter)
- 12:07 pm

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.