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
Add a comment  | 

1 Answer 1

Reset to default 0

From 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