月別アーカイブをスクロールで月ごとに読み込みさせる方法です。
例えば今月の記事一覧をページを読み込んだ時表示しておき、最後までスクロールすると、
先月の記事一覧を読み込むといった感じです。
■index.phpなど
'post',
'date_query' => array(
array(
'year' => $year,
'month' => $month,
'day' => $day,
),
),
);
$the_query = new WP_Query($args);
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
■js
var href = today = new Date(),
current_year = today.getFullYear(),
current_month = today.getMonth() + 1;
$(function() {
$(window).scroll(function(ev) {
var $window = $(ev.currentTarget),
height = $window.height(),
scrollTop = $window.scrollTop(),
documentHeight = $(document).height();
if (documentHeight === height + scrollTop) {
current_month--;
if(current_month == 0){
current_year--;
current_month = 12;
}
console.log(current_year);
console.log(current_month);
jQuery.ajax({
type: 'post',
data: {
'today':today,
'year':current_year,
'current_month':current_month
},
success: function(data) {
data = JSON.parse(data);
jQuery(".section.container").append(data['html']);
}
});
return false;
}
});
});
■more.php
'ASC',
'post_type' => 'post',
'orderby' => 'date',
'posts_per_page' => -1,
'date_query' => array(
array(
'after' => array(
'year' => $this_year,
'month' => $current_month,
'day' => $first_day,
),
'before' => array(
'year' => $this_year,
'month' => $current_month,
'day' => $last_day,
),
'inclusive' => true,
),
),
));
$results = $mydata_past;
$html = "";
foreach ($results as $result) {
$html .= '';
$html .= '';
$html .= '';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
'.get_post_time('m/d','false',$result->ID).'
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '