Cross-promote your new blog posts automatically

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.



One Response

  1. Wednesday, May 23, 2007

     Huw Leslie

    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

Projects

Indianapolis Startup Weekend IndyDads 2008 Indiana Bloggers Census Blog Indiana 2008

Stuff to click

Win a Nintendo Wii from Mr. Noobie

LifeStream