0

我需要在单个模板中显示类似的内容,如果帖子属于杂志类别,则仅显示该类别中同一个月发布的所有帖子。我尝试了以下方法:

    <?php
    $current_year = get_the_date('j',$the_post->post_parent);
    $current_month = get_the_date('F',$the_post->post_parent);
    query_posts($query_string . '&cat=1700&order=DESC&year=$current_year&monthnum=$current_month');
    ?>

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; endif; ?>

<?php wp_reset_query(); ?>

提前致谢

4

1 回答 1

0

首先不要使用query_posts它没有问题和 IMO 乏善可陈;) 更多关于这里

尝试这个:

$today = getdate();
$args = array('monthnum' => $today["mon"], 'cat' => 1700, 'order' => 'DESC', 'year' => $today["year"]);
$the_query = new WP_Query( $args );

while ( $the_query->have_posts() ) :
$the_query->the_post();
echo '<li><a href="'.get_the_permalink().'">' . get_the_title() . '</a></li>';
endwhile;

wp_reset_postdata();
于 2013-03-12T17:48:32.880 回答