作成日に従って記事のナビゲーションを作成する Ajax 関数を作成しようとしているため、ユーザーは前の (古い) リンクと次の (新しい) リンクを使用して記事をナビゲートできます。
<div class="content clear">
<div class="article">
Article contents...
</div>
<a href="#Prev" id="prev" class="leftarrow" title="Previous">EELMINE<span class="arrow_left"></span></a>
<a href="#" id="bactolist" onClick="history.go(-1); return false;">Tagasi nimekirja juurde<span class="arrow_middle"></span></a>
<a href="#Next" id="next" class="rightarrow" title="Next">JÄRGMINE<span class="arrow_right"></span></a>
</div> <!-- End content -->
<script type="text/javascript">
$.ajax({
url: '/admin/api/site/articles.json?per_page=100',
dataType: 'json',
success: function(articles) {
$(articles).each(function(index, article) {
console.log(article);
$('div.article').fadeOut(0);
$('div.article:first').fadeIn(500);
$('a.leftarrow, a.rightarrow').click( function (ev) {
//prevent browser jumping to top
ev.preventDefault();
//get current visible item
var $visibleItem = $('div.article:visible');
//get total item count
var total = $('div.article').length;
//get index of current visible item
var index = $visibleItem.prevAll().length;
//if we click next increment current index, else decrease index
$(this).attr('href') === '#Next' ? index++ : index--;
//if we are now past the beginning or end show the last or first item
if (index === -1){
index = total-1;
}
if (index === total){
index = 0
}
//hide current show item
$visibleItem.hide();
//fade in the relevant item
$('div.article:eq(' + index + ')').fadeIn(500);
});
});
}
});
日付の値に従って記事を取得する機能を構築するのに苦労しています。
を使用しconsole.log(article)
て、次の値を取得します。
body: "..."
comments_count: 0
comments_url: "..."
created_at: "date and time ..."
excerpt: "..."
title: "..."
url: "..."
したがって、ナビゲーションに変数を使用できるはずcreated_at
ですが、今のところ方法がわかりません。何か案は?
使用した CMS: Edicy 注: CMS は PHP をサポートしていません。
編集: CMS 開発者ドキュメントによって提供される「ブログ」ページの記事一覧のサンプル。