我正在尋找一種方式顯示,並按周導航WordPress的帖子。WordPress的羣組按周發佈
我會每週發送4-6個帖子,我希望主頁顯示當週的帖子。之前的每個頁面都應顯示按周排序的一組帖子。
每週的帖子數量是不固定的,會有所不同,所以我不知道如何去做這件事。
在此先感謝!
我正在尋找一種方式顯示,並按周導航WordPress的帖子。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; ?>
非常感謝,這似乎工作得很好 - 唯一的問題是分頁。我會怎麼做呢? – Dimitra
不知道這是否會工作沒有測試但在這裏不用
<?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; ?>
這是偉大的。祝你好運。 – Strawberry