Created
June 23, 2017 23:48
-
-
Save tanshio/021920dade446ebec395eac0b5aec960 to your computer and use it in GitHub Desktop.
list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Template Name: リストページ | |
*/ | |
?> | |
<?php get_header(); ?> | |
<h1>追加リスト</h1> | |
<button id="js-add">リストの追加</button> | |
<ul id="js-list"> | |
</ul> | |
<script> | |
var $button = jQuery('#js-add'); | |
var $list = jQuery('#js-list'); | |
var per_page = 1; | |
var count = 0; | |
$button.on('click', function (e) { | |
count++; | |
jQuery.ajax({ | |
url:'/wp-json/wp/v2/posts?_embed&per_page='+per_page+'&page='+count, | |
type:'get' | |
}) | |
.done(function(data){ | |
console.log(data.length);//データのリスト | |
data.forEach(function(item){ | |
$list.append('<li><a href="+item.title.link+">'+item.title.rendered+'</a></li>') | |
}) | |
}) | |
.fail(function(data){ | |
console.log(data); | |
$button.prop('disabled',true);//上限以上になったらボタンを押させない | |
}); | |
}) | |
</script> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment