Adrian Florescu
Adrian Florescu

Reputation: 4492

PHP Script to Get Latest Post Featured Image and Link form WP blogs

I have 2 (Wordpress) blogs on the same server and a landing page with 2 images.
One goes to first blog, the next one to the second blog.

Is there any way I can get in the first image, the post-thumbnail and link from the first post from the first blog and same thing from the second blog for the other image?

Thank you!

Upvotes: 0

Views: 812

Answers (1)

ariefbayu
ariefbayu

Reputation: 21979

Let's say, you have blog at:

and you have landing page at:

You will need to create 2 files:

  • /home/username/example31.com/index.php
  • /home/username/example31.com/index_test_wordpress.php

And both will have code, something like this:

  1. on your /home/username/example31.com/index.php, write:

    <?php
    echo file_get_contents('http://example31.com/index_test_wordpress.php');
    require_once("/home/username/example12.com/wp-load.php");
    echo  str_repeat("<br />", 10);
    $posts = wp_get_recent_posts( array('numberposts'=>1, 'post_status'=>'publish') );
    print_r($posts);
    ?>
    
  2. on your /home/username/example31.com/index_test_wordpress.php, write:

    <?php
    require_once("/home/username/example.com/wp-load.php");
    $posts = wp_get_recent_posts( array('numberposts'=>1, 'post_status'=>'publish') );
    print_r($posts);
    ?>
    

Note:

  1. I use file_get_contents to that file because I can't figure out a way to do two require() to wp-load.php, without conflicting each functions.
  2. For simplicity's sake, I only put print_r($posts). But, you should get the idea.

Upvotes: 1

Related Questions