WordPressでこれを行うにはどうすればよいですか?
wp クエリを制限して、最近 1 年 (365 日) までの投稿のみを一覧表示し、365 日より古い投稿は一覧表示しません。
これのためのプラグインはありますか?お知らせ下さい。
WordPressでこれを行うにはどうすればよいですか?
wp クエリを制限して、最近 1 年 (365 日) までの投稿のみを一覧表示し、365 日より古い投稿は一覧表示しません。
これのためのプラグインはありますか?お知らせ下さい。
過去 30 日間の投稿を一覧表示する方法を示す codex の例があります: http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters
ニーズに合わせて調整する必要があります。たとえば、(テストされていません):
// Create a new filtering function that will add our where clause to the query
function filter_where( $where = '' ) {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-1 year')) . "'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $query_string );
remove_filter( 'posts_where', 'filter_where' );
<?php
$date1yrback = date('Y-m-d',strtotime(date("Y-m-d", mktime()) . " - 365 day")); // Find Date 1 year back
$countp = 0;
if ( have_posts() ) : while ( have_posts() ) : the_post();
$my_date = the_date('Y-m-d', FALSE); //Find Post Date
if($my_date > $date1yrback) //Check if Post date is greater than date year back
{
echo "<h1>".the_title()."</h2>";
echo "<p>".the_content()."</p>";
$countp++; //Increment counter as post in above criteria is found
}
endwhile; endif;
if($countp == 0)
{
?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php
}
?>