【发布时间】:2014-08-16 12:03:38
【问题描述】:
我正在寻找一种按周显示和浏览 wordpress 帖子的方式。
我将每周发布 4-6 个帖子,我希望主页显示该周的帖子。之前的每一页都应该显示一组按周排序的帖子。
每周的帖子数量不是固定的,并且会有所不同,所以我不知道该怎么做。
提前致谢!
【问题讨论】:
-
太好了。祝你好运。
我正在寻找一种按周显示和浏览 wordpress 帖子的方式。
我将每周发布 4-6 个帖子,我希望主页显示该周的帖子。之前的每一页都应该显示一组按周排序的帖子。
每周的帖子数量不是固定的,并且会有所不同,所以我不知道该怎么做。
提前致谢!
【问题讨论】:
这样的东西是你的追求
<?php
$week = date('W');
$year = date('Y');
$the_query = new WP_Query( 'year=' . $year . '&w=' . $week );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?> "><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
【讨论】:
不确定这是否可行,但未经过测试
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$week = date('W');
$year = date('Y');
$the_query = new WP_Query( 'posts_per_page' => 50, 'paged' => $paged, 'year=' . $year . '&w=' . $week );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?> "><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
【讨论】: