2012-01-25 7 views
1

私はなぜWordPressに30日以上の新しい投稿を表示するのが難しいのか理解しようとしていますが、実際には2番目の目を使うことができます。私は次のコードを使用していますが、何も私のサイトに表示されていません。WordPress - 30日より後の投稿を表示する

<?php 
// Create a new filtering function that will add our where clause to the query 
function filter_where($where = '') { 
// posts in the last 30 days 
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; 
return $where; 
} 

add_filter('posts_where', 'filter_where'); 
$the_query = new WP_Query($query_string); 
remove_filter('posts_where', 'filter_where'); 
?> 


<?php if ($the_query->have_posts()) : ?> 

    <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> 


     <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> 
      <h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 
      <div class="meta"> 
      <span class="date"> 
       <strong><?php the_time('d'); ?></strong> 
       <strong><?php the_time('M'); ?></strong> 
      </span> 


      </div> 

      <div class="entry"> 
      <?php if (function_exists('get_the_image')) { 
     get_the_image(array('custom_key' => array('post_thumbnail'), 'default_size' => 'full', 'image_class' => 'alignleft', 'width' => '170', 'height' => '155')); } 
     ?> 

       <?php the_content('Read More'); ?> 
      </div> 


     </div> 

    <?php endwhile; ?> 

    <div class="navigation"> 
    <?php 
     include('includes/wp-pagenavi.php'); 
     if(function_exists('wp_pagenavi')) { wp_pagenavi(); } 
    ?> 
    </div> 

<?php else : ?> 

    <h2 class="center">Not Found</h2> 
    <p class="center">Sorry, but you are looking for something that isn't here.</p> 
    <?php get_search_form(); ?> 

<?php endif; ?> 

答えて

1

あなたのやり方は上手く見えます。引数としてposts_per_page => -1を入れてみてください。私にとって

次作品:

function filter_where($where = '') { 
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; 
    return $where; 
} 

add_filter('posts_where', 'filter_where'); 
$args = array(
    'posts_per_page' => -1, 
); 
$the_query = new WP_Query($args); 
remove_filter('posts_where', 'filter_where'); 

while ($the_query->have_posts()) { 
    $the_query->the_post(); 
    // do stuff 
} 

はそれがお役に立てば幸いです。

+0

が機能しなかったことは、残念ながら、あなたの助けに感謝が、動作します。私は最後の数日から約4〜5の記事を持っていて、彼らは現れていないので、私は絶対に困惑しています。非常に簡単なはずですが、なんらかの理由で私は時間があるんです。 – user965879

+0

あなたのコードの周りに何かがあるかもしれません。最小の実例を試してみてください。すべてのプラグインを無効にし、結果を出力する関数にすべてを入れ、最後に 'exit()'をつけて、 'add_action( 'wp'、 'your_func');でフックします。本当に馬鹿なことかもしれません。 = D – vmassuchetto

7
<?php 
    function filter_where($where = '') { 
    //posts in the last 30 days 
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; 
    return $where; 
    } 
add_filter('posts_where', 'filter_where'); 
query_posts($query_string); 
?> 

これは

関連する問題