简体   繁体   English

下一个如何访问博客发布者链接列表

[英]how to access blogger post link list with next prev

I have simple blogger json feed 我有简单的Blogger JSON Feed

<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>

This code display my total post link list. 此代码显示我的总帖子链接列表。 how to divide all post link into 5 link list and access all post link with next prev button 如何将所有发布链接分为5个链接列表,并使用下一个上一个按钮访问所有发布链接

A easy solution would be to use a jQuery pagination library, like this one http://flaviusmatis.github.io/simplePagination.js/ for example. 一种简单的解决方案是使用jQuery分页库,例如http://flaviusmatis.github.io/simplePagination.js/ It creates a pagination and even styles it. 它创建了一个分页,甚至设置了样式。 In this Question ( https://stackoverflow.com/a/20896955/1679286 ) the usage is explained a bit more in detail, if the project page isn't clear enough. 如果项目页面不够清晰,则在本问题( https://stackoverflow.com/a/20896955/1679286 )中对用法进行了详细说明。

Here a mini Demo (how it could work) 这是一个迷你演示(如何工作)

 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> 

Optional: Another solution that is not 100% save, since order of the post could change, would be not loading all post using the query parameter start-index mentioned in the google References https://developers.google.com/gdata/docs/2.0/reference#Queries 可选:另一种不是100%保存的解决方案,因为帖子的顺序可能会更改,因此不会使用Google参考https://developers.google.com/gdata/docs中提到的查询参数start-index加载所有帖子/2.0/reference#查询

Creating this link: 创建此链接:
https://techtovillage.blogspot.com/feeds/posts/default?orderby=published&max-results=5&start-index=1&alt=json-in-script&callback=mycallback
And adjusting the code to change to only load the current posts, with Ajax calls (jQuery JSONP or so), so that the start-index is incremented / decremented by 5 depending on the Button/Link that was clicked 并调整代码以仅使用Ajax调用(jQuery JSONP左右)加载当前帖子,以使start-index根据单击的Button / Link递增/递减5。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM