admin管理员组文章数量:1410725
I have the static website template on the following domain : example and I have wordpress site in the sub domain : sub.example I want a code to get the latest post ( just post title ) from the WordPress site to the static site in a dynamic way and when visitor clicked, go to the WordPress site to see full post .
I have the static website template on the following domain : example and I have wordpress site in the sub domain : sub.example I want a code to get the latest post ( just post title ) from the WordPress site to the static site in a dynamic way and when visitor clicked, go to the WordPress site to see full post .
Share Improve this question asked Jan 21, 2020 at 9:28 wordpress loverwordpress lover 1 1- did you see my answer? does it work for you? – Andrea Somovigo Commented Jan 22, 2020 at 10:17
1 Answer
Reset to default 0From your static page you can make a jQuery GET request ( using jQuery is not mandatory though can be the easiest way) to the default endpoint posts
of the WP rest of your installation.
More info about WP REST here: https://developer.wordpress/rest-api/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<ul id="remoteList">
</ul>
<script>
jQuery.get('//sub.example/wp-json/wp/v2/posts').then(
function(response){
jQuery.each(response,function(index,post){
console.log(post);
$('#remoteList').append('<li><a href="'+post.link+'" target="_blank">'+post.title.rendered+'</a></li>')
})
}
);
</script>
</body>
</html>
本文标签: phpWordPress recent post
版权声明:本文标题:php - WordPress recent post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744816082a2626705.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论