Wordpress同月显示相同类别的帖子

时间:2013-03-12 17:31:49

标签: wordpress categories

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

    <?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(); ?>

提前致谢

1 个答案:

答案 0 :(得分:0)

要开始,请不要使用query_posts没有问题,而且IMO表现平平;)更多关于here

试试这个:

$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();