admin管理员组文章数量:1130349
I'm trying to make my own theme and I've created an archive template that works fairly well. The template shows all posts, but the problem is that all posts will show if I go to /2018/11/ (posts were created in different months) even though I've added monthnum and year in my query_posts.
<?php
/**
* Template Name: Blog Posts
*/
?>
<?php query_posts('post_type=post&post_status=publish&posts_per_page=10&monthnum='. get_query_var('month') .'&year='. get_query_var('year')); ?>
<?php if( have_posts() ): ?>
<?php while( have_posts() ): the_post(); ?>
<div id="post-<?php get_the_ID(); ?>" <?php post_class(); ?>>
<div class="row featurette">
<div class="col-md-7">
<h2 class="featurette-heading"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="lead"><?php echo get_the_excerpt(); ?></p>
</div>
<div class="col-md-5">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(500,500, 'class' => " img-responsive center-block") ); ?></a>
</div>
</div>
<div class="featurette-divider"></div>
</div><!-- /#post-<?php get_the_ID(); ?> -->
<?php endwhile; ?>
<div class="navigation">
<span class="newer"><?php previous_posts_link(__('« Newer','example')) ?></span> <span class="older"><?php next_posts_link(__('Older »','example')) ?></span>
</div><!-- /.navigation -->
<?php else: ?>
<div id="post-404" class="noposts">
<p><?php _e('None found.','example'); ?></p>
</div><!-- /#post-404 -->
<?php endif; wp_reset_query(); ?>
I'm trying to make my own theme and I've created an archive template that works fairly well. The template shows all posts, but the problem is that all posts will show if I go to /2018/11/ (posts were created in different months) even though I've added monthnum and year in my query_posts.
<?php
/**
* Template Name: Blog Posts
*/
?>
<?php query_posts('post_type=post&post_status=publish&posts_per_page=10&monthnum='. get_query_var('month') .'&year='. get_query_var('year')); ?>
<?php if( have_posts() ): ?>
<?php while( have_posts() ): the_post(); ?>
<div id="post-<?php get_the_ID(); ?>" <?php post_class(); ?>>
<div class="row featurette">
<div class="col-md-7">
<h2 class="featurette-heading"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="lead"><?php echo get_the_excerpt(); ?></p>
</div>
<div class="col-md-5">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(500,500, 'class' => " img-responsive center-block") ); ?></a>
</div>
</div>
<div class="featurette-divider"></div>
</div><!-- /#post-<?php get_the_ID(); ?> -->
<?php endwhile; ?>
<div class="navigation">
<span class="newer"><?php previous_posts_link(__('« Newer','example')) ?></span> <span class="older"><?php next_posts_link(__('Older »','example')) ?></span>
</div><!-- /.navigation -->
<?php else: ?>
<div id="post-404" class="noposts">
<p><?php _e('None found.','example'); ?></p>
</div><!-- /#post-404 -->
<?php endif; wp_reset_query(); ?>
本文标签: queryMy archives page won39t sort posts by month
版权声明:本文标题:query - My archives page won't sort posts by month 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749187417a2329619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论