Wordpress: döngü yalnızca mesaj X günlük eski içerir

1 Cevap php

Benim wordpress frontpage son X günün sadece mesajları göstermek istiyorum. Bir hafta, diyelim, yani 7 günlük en.

What's the propper way to tell wordpress to select only the posts in the last X day's in the loop?

Şu anda, o yalak kesmek çalışma var, ama o pagination kadar karışıyor. Sonraki sayfaya gitmek doğru mesajları seçmez.

//Hack found on the bottom of http://codex.wordpress.org/Template_Tags/query_posts
function filter_where($where = '') {
    //posts in the last 7 days
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
if ( have_posts() ) : while ( have_posts() ) : the_post();
... and the usual

1 Cevap

Aşağıdaki ile Yapabilecekleriniz kısmi başarı:

function filter_where($where = '') {
  $date_split = date('Y-m-d', strtotime('-7 days'));
  if (is_paged()) {
    $where .= " AND post_date < '" . $date_split . "'";
  } else {
    $where .= " AND post_date > '" . $date_split . "'";
  }
  return $where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);

Benim ana sayfa son 7 gün içinde mesajlarını gösterir, beklendiği gibi sayfa / 1 bir devamı olarak o gün ve sayfa / 2 çalışmalarından sonra mesajlarını gösteren sayfa / 1 başlar.