Display recent WordPress Posts links on another WordPress Blog

So you’ve got a lot of Blogs or sites in WordPress and you want to share links to posts from one site to the other? With the following script you can Display recent WordPress Posts links on another WordPress Blog!

I’ve got several blogs! And I don’t like crossposting! But I do like showing links from one blog to the other.

So I do like, crosslinking yes! But there is not a very good sollution to display your wordpress posts on other wordpress blogs.

So I created a small script do do this just for you!

Display recent WordPress Posts links

Before you head off to my script there are a few small steps to make before you can use my script.

First you will have to install a plugin on your site called Snippets. With this plugin you can add extra functionality to your site.

Installed it? Great! You need some information from your other site (where you want to display the post links from) to get my script working.

You need the following 4 items from your wp_config.php to get this up and running.

  • DB_NAME
  • DB_USER
  • DB_PASSWORD
  • $table_prefix

You get this information from your wp_config file. It starts at about line 19. You’ll need a ftp connection to your server or you can use the plugin WP Config File Editor on your site to get this information.

When the two sites are on different servers you also need to fill in the Host part. When on the same server you can leave localhost. But when not… you will need to fill in the IP address of the other server.

So create a new snippet within the snippet plugin with the code below. Fill in the blanks (XXXXXXX) from your wp_config file.

And then you’re all done!

Want to show off some links to posts on the other site?

Just add

[show-postsothersite]

To your post or sidebar / footer widgets.

You can add some extra variables to the outcome, like name (of the site) and number of links to show.

You can add these very easily like:

[show-postsothersite sitename='vandersluijs.nl' limit='10']

And your all done!

function showPostsOtherSite($atts) {
  
    //this information is found in the config.php of your other wordpress blog
	$db_username 	= 'XXXXXXXXXX';
	$db_password 	= 'XXXXXXXXXX';
	$db_database 	= 'XXXXXXXXXX';  
	$db_host 	= 'localhost'; //leave localhost or type IP from different server!
  
	$db_prefix 	= 'XX_'; //something like wp_ (don't forget the _ sign)
	


//###########################################################################//	
//LIKE MY SCRIPT? PLEASE BUY ME A CUP OF COFFEE, DONATE WITH PAYPAL!         //
//PLEASE DONATE 1 EURO TO =>     http://snurl.eu/donate-one-euro     	     //
//THANK YOU SO MUCH!!!!			   				     //
//				 					     //
//NO MORE EDITING FROM HERE						     //
//###########################################################################//	

    global $wpdb;	
    extract( shortcode_atts( array('site' => 'site', 
    				   'sitename' => 'sitename', 
    				   'limit' => 'limit'), $atts));
  
  	$limit = (int) $limit;
  	if(!isset($limit) || $limit <= 0){
	    $limit = '5'; // only used when there's no limit in the attributes
	}
  
  	$newdb = new wpdb( $db_username , $db_password , $db_database , $db_host );

    $table_name = $db_prefix . "posts";
    
    $sql = "SELECT * FROM {$table_name} WHERE post_type='post' AND post_status='publish' 
    	    ORDER BY id DESC LIMIT {$limit}";

    $rows = (array) $newdb->get_results( $sql, ARRAY_A );

	$str = "";

	$str .= "<h4 class='widget-title'>Posts from {$sitename}</h4>";
  
  	if(!isset($rows) || count($rows)<=0){
		$str .= "Sorry, no posts to show!";
	}else{
		$str .= "<ul>";
		foreach($rows as $row){
		        $str .= "<li>";
		        $str .= "<a href='{$row['guid']}' target='_blank'>";
		        $str .= $row['post_title'];
		        $str .= "</a>";
		        $str .= "</li>";     
    		}

		//DID YOU DONATE? THANK YOU, YOU CAN REMOVE THE FOLLOWING LINES
	 	$str .= "<li>
	 		     <a href='http://vandersluijs.nl' target='_blank'>
       			        Display recent Wordpress Posts links on another WordPress Blog
	 	    	     </a>
	 	    	 </li>";
			//STOP HERE
			  
    		$str .= "</ul>";
	}

    return $str;
}
add_shortcode('show-postsothersite', 'showPostsOtherSite');	

WordPress Posts links on another WordPress Blog example

So wanna see it work? Here you can see some examples of my script working form these following wordpress blogs :

  • dezeeuwsefotograaf.nl
  • itheo.nl
  • 40enfit.nl

 

Artikelen van 40 en fit!

Artikelen van iTheo

Sorry, no posts to show!

Artikelen van De Zeeuwse Fotograaf!

Sorry, no posts to show!

Like this script? Please Donate one euro for a cup of coffee! Thank you!

Nerd Herder ☆ Scrum Master ☆ Jira Ninja ☆ Freeletics evangelist ☆ Photo Shooter ☆ Dad ☆ Husband ☆ Zookeeper ☆ Blogger Fit Dutch Bodies ☆ Dutch

Site Footer