在网上搜索有关如何做到这一点的想法。这就是我想要做的事情:
WP网站" A"被用作我运行的其他WP站点的门户网站,它也将拥有它自己的博客帖子。
WP网站" B"是有活跃博客的两个外部网站中的第一个。帖子有缩略图和标题。
WP网站" C"是有活跃博客的两个外部网站中的第二个。帖子有缩略图和标题。
WP网站" A"将在主页上有一个砖石风格的帖子列表,缩略图和链接的帖子标题。我想从网站上删除新的博客文章" B"和" C"并以相同的方式显示它们:缩略图,帖子标题和指向外部网站的链接。我还想让它以升序的日期顺序显示它们,随着新博客的创建而散布在一起。
是否有人建议如何执行此操作,或如何将外部帖子提供给其他博客?如果有帮助,所有这些博客都在同一个托管帐户上,并且对其数据库具有相同的访问权限。我一直在寻找一些基于RSS的解决方案(实际上已经使用过其中一个解决方案之前将单个帖子拉到主页中,但这比其中涉及的更多),但我不确定如何将它们集成到Blog" A"的结构这样它们就可以在同一个砌体网格中组合在一起。
感谢您的帮助。
答案 0 :(得分:2)
您可以查看WP REST API(http://v2.wp-api.org)。这正是您正在寻找的。使用WP REST API,您可以从您管理的任何站点获取帖子的每个元素,并将其显示在任何其他站点上。 (但是你也应该实现某种形式的身份验证!)
示例请求:
http://www.example.com/wp/wp-json/wp/v2/venue
“venue”是我在真实代码中使用的自定义帖子类型。该示例请求是为了从站点获取所有场地。
回复示例:
[
{
"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’s OK. 7765e546uzfkjglh</p>\n<p> </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’s OK. 7765e546uzfkjglh </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&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&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&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&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 – 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 – 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&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 – it is made of a custom post type, and I get it with REST API.</p>\n"
},
"excerpt": {
"rendered": "<p>This is a venue – 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
}
]
}
}
]
注意: - 上面的示例结果根据我的需要进行了一些定制 - 因此您可能会看到一些其他结果。 - 单个场地的请求看起来像这样:
http://www.example.com/wp/wp-json/wp/v2/venue/20
正如您所看到的,您可以从其他网站获取所需的每条信息 - 您甚至可以根据自己的喜好自定义响应。