mg33
mg33

Reputation: 21

Display other WP site blog posts in one WP blog

Been scouring the Internet for ideas on how to do this. Here's what I'd like to do:

WP Site "A" to be used as a portal of sorts to other WP sites I run, and it will also have it's own blog posts.

WP Site "B" is the first of two external sites with an active blog. Posts have thumbnails and titles.

WP Site "C" is the second of two external sites with an active blog. Posts have thumbnails and titles.

WP Site "A" will have a masonry-style post listing on the homepage, of thumbnails, and post titles that link. I'd like to pull new blog posts from sites "B" and "C" and display them in the same manner: thumbnails, post titles, and links that would lead to the external site. I'd also want this to display them in ascending date order, interspersed together as the new blogs are created.

Does anyone have a suggestion on how to do this, or how to feed external posts into another blog? If it helps, all of these blogs are on the same hosting account, with the same access to their DB's. I have been finding a few RSS-based solutions (and in fact have used one of them to pull single posts into a homepage before, but this is more involved than that), but I'm not sure how to integrate them into the structure of Blog "A" so that they are all grouped together in the same masonry grid.

Thanks for your help.

Upvotes: 0

Views: 97

Answers (1)

muka.gergely
muka.gergely

Reputation: 8329

You can look at WP REST API (http://v2.wp-api.org). This is exactly what you are looking for. With WP REST API you can get EVERY element of a post from any site you manage, and display it on any other site. (But you should also implement some form of authentication!)

Example request:

http://www.example.com/wp/wp-json/wp/v2/venue

"venue" is a custom post type that I use in the real code. The example request is made to get all the venues from the site.

Example response:

    [
  {
    "id": 20,
    "date": "2016-06-08T16:37:23",
    "date_gmt": "2016-06-08T16:37:23",
    "guid": {
      "rendered": "http://www.example.com/wp/?post_type=venue&p=20"
    },
    "modified": "2016-06-20T11:45:22",
    "modified_gmt": "2016-06-20T11:45:22",
    "slug": "aquarium-club",
    "type": "venue",
    "link": "http://www.example.com/wp/venue/aquarium-club/",
    "title": {
      "rendered": "Aquarium Club"
    },
    "content": {
      "rendered": "<p>Aquarium Club. That&#8217;s OK. 7765e546uzfkjglh</p>\n<p>&nbsp;</p>\n<style>\n.gmap-iframe-container {\nmax-width: 100%;\n}\n.gmap-iframe {\nwidth: 100%;\nheight: 200px;\nmin-width:100%;\n}\n</style>\n<div class=\"gmap-iframe-container\">\n<iframe src=\"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2695.565888030695!2d19.052103115616678!3d47.49836967917771!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x4741dc402a04eee3%3A0x6869564cd433693c!2sAkv%C3%A1rium+Klub!5e0!3m2!1shu!2shu!4v1466147278469\" frameborder=\"0\" style=\"border:0\" allowfullscreen class=\"gmap-iframe\"></iframe></p>\n"
    },
    "excerpt": {
      "rendered": "<p>Aquarium Club. That&#8217;s OK. 7765e546uzfkjglh &nbsp;</p>\n"
    },
    "featured_media": 0,
    "menu_order": 0,
    "format": "standard",
    "tags": [],
    "meta_data": {
      "youtube_embed": "https://www.youtube.com/embed/xBW7DglTDGs"
    },
    "_links": {
      "self": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue/20"
        }
      ],
      "collection": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue"
        }
      ],
      "about": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
        }
      ],
      "wp:attachment": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=20"
        }
      ],
      "wp:term": [
        {
          "taxonomy": "post_tag",
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=20"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  },
  {
    "id": 18,
    "date": "2016-06-08T15:55:04",
    "date_gmt": "2016-06-08T15:55:04",
    "guid": {
      "rendered": "http://www.example.com/wp/?post_type=venue&#038;p=18"
    },
    "modified": "2016-06-08T15:55:04",
    "modified_gmt": "2016-06-08T15:55:04",
    "slug": "durer-kert",
    "type": "venue",
    "link": "http://www.example.com/wp/venue/durer-kert/",
    "title": {
      "rendered": "Dürer Kert"
    },
    "content": {
      "rendered": ""
    },
    "excerpt": {
      "rendered": ""
    },
    "featured_media": 19,
    "menu_order": 0,
    "format": "standard",
    "tags": [],
    "meta_data": {
      "youtube_embed": "https://www.youtube.com/embed/w9saGGpnKlk"
    },
    "_links": {
      "self": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue/18"
        }
      ],
      "collection": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue"
        }
      ],
      "about": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
        }
      ],
      "wp:featuredmedia": [
        {
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/media/19"
        }
      ],
      "wp:attachment": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=18"
        }
      ],
      "wp:term": [
        {
          "taxonomy": "post_tag",
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=18"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  },
  {
    "id": 15,
    "date": "2016-06-08T14:52:40",
    "date_gmt": "2016-06-08T14:52:40",
    "guid": {
      "rendered": "http://www.example.com/wp/?post_type=venue&#038;p=15"
    },
    "modified": "2016-06-08T15:41:27",
    "modified_gmt": "2016-06-08T15:41:27",
    "slug": "kobuci-kert",
    "type": "venue",
    "link": "http://www.example.com/wp/venue/kobuci-kert/",
    "title": {
      "rendered": "KOBUCI Kert"
    },
    "content": {
      "rendered": "<p>This is KOBUCI Kert.</p>\n"
    },
    "excerpt": {
      "rendered": "<p>This is KOBUCI Kert.</p>\n"
    },
    "featured_media": 17,
    "menu_order": 0,
    "format": "standard",
    "tags": [],
    "meta_data": {
      "youtube_embed": "https://www.youtube.com/embed/zwNBKh6ghOY"
    },
    "_links": {
      "self": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue/15"
        }
      ],
      "collection": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue"
        }
      ],
      "about": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
        }
      ],
      "wp:featuredmedia": [
        {
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/media/17"
        }
      ],
      "wp:attachment": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=15"
        }
      ],
      "wp:term": [
        {
          "taxonomy": "post_tag",
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=15"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  },
  {
    "id": 13,
    "date": "2016-06-08T14:12:38",
    "date_gmt": "2016-06-08T14:12:38",
    "guid": {
      "rendered": "http://www.example.com/wp/?post_type=venue&#038;p=13"
    },
    "modified": "2016-06-08T14:12:38",
    "modified_gmt": "2016-06-08T14:12:38",
    "slug": "mupa",
    "type": "venue",
    "link": "http://www.example.com/wp/venue/mupa/",
    "title": {
      "rendered": "MÜPA"
    },
    "content": {
      "rendered": "<p>MÜPA is MÜPA. Not bad from a building, is it? A lot of concerts and stuff.</p>\n"
    },
    "excerpt": {
      "rendered": "<p>MÜPA is MÜPA. Not bad from a building, is it? A lot of concerts and stuff.</p>\n"
    },
    "featured_media": 14,
    "menu_order": 0,
    "format": "standard",
    "tags": [],
    "meta_data": {
      "youtube_embed": "https://www.youtube.com/embed/YnOW2rUXuSg"
    },
    "_links": {
      "self": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue/13"
        }
      ],
      "collection": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue"
        }
      ],
      "about": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
        }
      ],
      "wp:featuredmedia": [
        {
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/media/14"
        }
      ],
      "wp:attachment": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=13"
        }
      ],
      "wp:term": [
        {
          "taxonomy": "post_tag",
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=13"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  },
  {
    "id": 8,
    "date": "2016-06-07T08:36:40",
    "date_gmt": "2016-06-07T08:36:40",
    "guid": {
      "rendered": "http://www.example.com/wp/?post_type=venue&#038;p=8"
    },
    "modified": "2016-06-08T13:22:39",
    "modified_gmt": "2016-06-08T13:22:39",
    "slug": "some-venue",
    "type": "venue",
    "link": "http://www.example.com/wp/venue/some-venue/",
    "title": {
      "rendered": "National Concert Hall"
    },
    "content": {
      "rendered": "<p>This is the next venue for REST API. Just to see more than one. This should be the general description of this venue. This is the venue &#8211; what is it? 5324</p>\n"
    },
    "excerpt": {
      "rendered": "<p>This is the next venue for REST API. Just to see more than one. This should be the general description of this venue. This is the venue &#8211; what is it? 5324</p>\n"
    },
    "featured_media": 9,
    "menu_order": 0,
    "format": "standard",
    "tags": [],
    "meta_data": {
      "youtube_embed": "https://www.youtube.com/embed/camVVzjGheQ"
    },
    "_links": {
      "self": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue/8"
        }
      ],
      "collection": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue"
        }
      ],
      "about": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
        }
      ],
      "wp:featuredmedia": [
        {
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/media/9"
        }
      ],
      "wp:attachment": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=8"
        }
      ],
      "wp:term": [
        {
          "taxonomy": "post_tag",
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=8"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  },
  {
    "id": 7,
    "date": "2016-06-07T08:33:13",
    "date_gmt": "2016-06-07T08:33:13",
    "guid": {
      "rendered": "http://www.example.com/wp/?post_type=venue&#038;p=7"
    },
    "modified": "2016-06-08T13:20:27",
    "modified_gmt": "2016-06-08T13:20:27",
    "slug": "orchestra-hall",
    "type": "venue",
    "link": "http://www.example.com/wp/venue/orchestra-hall/",
    "title": {
      "rendered": "Music Academy"
    },
    "content": {
      "rendered": "<p>This is a venue &#8211; it is made of a custom post type, and I get it with REST API.</p>\n"
    },
    "excerpt": {
      "rendered": "<p>This is a venue &#8211; it is made of a custom post type, and I get it with REST API.</p>\n"
    },
    "featured_media": 11,
    "menu_order": 0,
    "format": "standard",
    "tags": [],
    "meta_data": {
      "youtube_embed": "https://www.youtube.com/embed/ZL6BFCxNGZ8"
    },
    "_links": {
      "self": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue/7"
        }
      ],
      "collection": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/venue"
        }
      ],
      "about": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
        }
      ],
      "wp:featuredmedia": [
        {
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/media/11"
        }
      ],
      "wp:attachment": [
        {
          "href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=7"
        }
      ],
      "wp:term": [
        {
          "taxonomy": "post_tag",
          "embeddable": true,
          "href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=7"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  }
]

Note: -- the example result above is a bit customised to my needs - so you may see a bit other result. -- a request for a single venue would look something like this:

http://www.example.com/wp/wp-json/wp/v2/venue/20

As you can see you can get every piece of information you need from the other site - and you can even customise the response to your liking.

Upvotes: 2

Related Questions