Wordpress - 显示超过30天的帖子

use*_*879 1 wordpress wordpress-theming

我疯狂地想弄清楚为什么我很难让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; ?>
Run Code Online (Sandbox Code Playgroud)

小智 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);
?>
Run Code Online (Sandbox Code Playgroud)

这有效