如何访问博主 post link 列表和下一个上一个
how to access blogger post link list with next prev
我有简单的博主 json 提要
<script type='text/javascript'>
function mycallback(json) {
for (var i = 0; i < json.feed.entry.length; i++) {
for (var j = 0; j < json.feed.entry[i].link.length; j++) {
if (json.feed.entry[i].link[j].rel == 'alternate') {
var postUrl = json.feed.entry[i].link[j].href;
break;
}
}
var postTitle = json.feed.entry[i].title.$t;
var item = '<ul><li><a href=' + postUrl + '>' + postTitle + '</a></li></ul>';
document.write(item);
}
}
</script>
<button type="button">Prev</button>
<button type="button">Next</button>
<h2>Recent Post</h2>
<script src='https://techtovillage.blogspot.com/feeds/posts/default?orderby=published&max-results=1000&alt=json-in-script&callback=mycallback'></script>
此代码显示我的总 post link 列表。
如何将所有 post link 分成 5 个 link 列表并使用下一个按钮
访问所有 post link
一个简单的解决方案是使用 jQuery 分页库,比如这个 http://flaviusmatis.github.io/simplePagination.js/ for example. It creates a pagination and even styles it. In this Question () 如果项目页面不够清晰,用法会更详细地解释一下。
这是一个迷你演示(它是如何工作的)
var listInfo = {
itemsOnPage:4,
items:[]
};
function mycallback(json) {
var tableContent = "";
listInfo.itemsCount = json.feed.entry.length
for (var i = 0; i < listInfo.itemsCount; i++) {
var postTitle = json.feed.entry[i].title.$t;
for (var j = 0; j < json.feed.entry[i].link.length; j++) {
if (json.feed.entry[i].link[j].rel === 'alternate') {
var postUrl = json.feed.entry[i].link[j].href;
break;
}
}
tableContent += '<tr><td><a href=' + postUrl + '>' + postTitle + '</a></td></tr>';
}
$("#recentPost").html(tableContent);
listInfo.items = $("#recentPost tr");
console.info(listInfo)
$("#pagination").pagination({
items: listInfo.itemsCount,
itemsOnPage: listInfo.itemsOnPage,
cssStyle:"light-theme",
onPageClick: function(pageNumber) {
var from = listInfo.itemsOnPage * (pageNumber - 1);
var to = from + listInfo.itemsOnPage;
listInfo.items.hide()
.slice(from, to).show();
}
})
.pagination('selectPage', 1);
}
$.ajax({
url: "https://techtovillage.blogspot.com/feeds/posts/default?orderby=published&max-results=16&alt=json-in-script",
jsonp: "callback",
dataType: "jsonp",
success: function( response ) {
mycallback(response);
}
});
<link href="https://rawgit.com/flaviusmatis/simplePagination.js/master/simplePagination.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/flaviusmatis/simplePagination.js/master/jquery.simplePagination.js"></script>
<h2>Recent Post</h2>
<table id="recentPost">
</table>
<div id="pagination"></div>
可选:
另一个不是 100% 保存的解决方案,因为 post 的顺序可能会改变,所以不会使用 google 中提到的查询参数 start-index
加载所有 post 参考 https://developers.google.com/gdata/docs/2.0/reference#Queries
创建此 link:
https://techtovillage.blogspot.com/feeds/posts/default?orderby=published&max-results=5&start-index=1&alt=json-in-script&callback=mycallback
并调整代码以更改为仅加载当前 posts,使用 Ajax 调用(jQuery JSONP 左右),以便 start-index
递增/递减 5取决于被点击的Button/Link
我有简单的博主 json 提要
<script type='text/javascript'>
function mycallback(json) {
for (var i = 0; i < json.feed.entry.length; i++) {
for (var j = 0; j < json.feed.entry[i].link.length; j++) {
if (json.feed.entry[i].link[j].rel == 'alternate') {
var postUrl = json.feed.entry[i].link[j].href;
break;
}
}
var postTitle = json.feed.entry[i].title.$t;
var item = '<ul><li><a href=' + postUrl + '>' + postTitle + '</a></li></ul>';
document.write(item);
}
}
</script>
<button type="button">Prev</button>
<button type="button">Next</button>
<h2>Recent Post</h2>
<script src='https://techtovillage.blogspot.com/feeds/posts/default?orderby=published&max-results=1000&alt=json-in-script&callback=mycallback'></script>
此代码显示我的总 post link 列表。 如何将所有 post link 分成 5 个 link 列表并使用下一个按钮
访问所有 post link一个简单的解决方案是使用 jQuery 分页库,比如这个 http://flaviusmatis.github.io/simplePagination.js/ for example. It creates a pagination and even styles it. In this Question () 如果项目页面不够清晰,用法会更详细地解释一下。
这是一个迷你演示(它是如何工作的)
var listInfo = {
itemsOnPage:4,
items:[]
};
function mycallback(json) {
var tableContent = "";
listInfo.itemsCount = json.feed.entry.length
for (var i = 0; i < listInfo.itemsCount; i++) {
var postTitle = json.feed.entry[i].title.$t;
for (var j = 0; j < json.feed.entry[i].link.length; j++) {
if (json.feed.entry[i].link[j].rel === 'alternate') {
var postUrl = json.feed.entry[i].link[j].href;
break;
}
}
tableContent += '<tr><td><a href=' + postUrl + '>' + postTitle + '</a></td></tr>';
}
$("#recentPost").html(tableContent);
listInfo.items = $("#recentPost tr");
console.info(listInfo)
$("#pagination").pagination({
items: listInfo.itemsCount,
itemsOnPage: listInfo.itemsOnPage,
cssStyle:"light-theme",
onPageClick: function(pageNumber) {
var from = listInfo.itemsOnPage * (pageNumber - 1);
var to = from + listInfo.itemsOnPage;
listInfo.items.hide()
.slice(from, to).show();
}
})
.pagination('selectPage', 1);
}
$.ajax({
url: "https://techtovillage.blogspot.com/feeds/posts/default?orderby=published&max-results=16&alt=json-in-script",
jsonp: "callback",
dataType: "jsonp",
success: function( response ) {
mycallback(response);
}
});
<link href="https://rawgit.com/flaviusmatis/simplePagination.js/master/simplePagination.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/flaviusmatis/simplePagination.js/master/jquery.simplePagination.js"></script>
<h2>Recent Post</h2>
<table id="recentPost">
</table>
<div id="pagination"></div>
可选:
另一个不是 100% 保存的解决方案,因为 post 的顺序可能会改变,所以不会使用 google 中提到的查询参数 start-index
加载所有 post 参考 https://developers.google.com/gdata/docs/2.0/reference#Queries
创建此 link:
https://techtovillage.blogspot.com/feeds/posts/default?orderby=published&max-results=5&start-index=1&alt=json-in-script&callback=mycallback
并调整代码以更改为仅加载当前 posts,使用 Ajax 调用(jQuery JSONP 左右),以便 start-index
递增/递减 5取决于被点击的Button/Link