WP REST APIとjQueryでサイト内のページを呼び出す

コード

<div>
    <script type="text/javascript">
      jQuery(function() {
          jQuery.getJSON( "https://haradaweb.com/web/wp-json/wp/v2/posts?per_page=100", function(result) {
              jQuery.each(result, function(i, item) {
                 jQuery("ul.post-list").append("<li>" + item.title.rendered + "</li>");
              });
          });
      });
    </script>
</div>
<h2>サイト内記事</h2>
<ul class="post-list"></ul>

コードの説明

jQuery.getJSON

はJavaScriptのjQuery.getメソッドをjson形式に限定したメソッドです。
jQuery.getメソッド はデータを読み込む働きがあります。

"https://haradaweb.com/web/wp-json/wp/v2/posts?per_page=100"

https://haradaweb.com/web/はデータを取得する先のURL、今回の場合はこのサイトです。

サイト内記事

    TOP

    This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

    Accept or Deny