2014-06-25 28 views
-2

我正在尋找一種方式顯示,並按周導航WordPress的帖子。WordPress的羣組按周發佈

我會每週發送4-6個帖子,我希望主頁顯示當週的帖子。之前的每個頁面都應顯示按周排序的一組帖子。

每週的帖子數量是不固定的,會有所不同,所以我不知道如何去做這件事。

在此先感謝!

+2

這是偉大的。祝你好運。 – Strawberry

回答

0

像這樣的東西是你的後

<?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; ?> 
+0

非常感謝,這似乎工作得很好 - 唯一的問題是分頁。我會怎麼做呢? – Dimitra

0

不知道這是否會工作沒有測試但在這裏不用

<?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; ?> 
+0

我剛剛嘗試過,但現在由於某種原因,所有帖子都在主頁上加載? – Dimitra

+0

您是否將posts_per_page更改爲您想要的號碼? –

+0

我現在這樣做了,但主要問題是我不知道每週會發布多少帖子,它總是會有所不同(這就是爲什麼我不能使用「正常」wordpress循環) – Dimitra