2011-01-24 26 views
0

試圖找出如何構建以我想要的格式顯示的歸檔頁面。我想顯示所有帖子,按日期排序。應該看起來像:Wordpress自定義歸檔格式

February 2010 
    6   Post-Title 
    3   Post-Title 

January 2010 
    29   Post-Title 
    etc... 

我很難搞清楚需要創建的循環的細節。我在Wordpress 3.0.4上。

回答

3

我一旦解決了這個爲WP 2.9.something這樣的:

是的!我知道:標記的縮進看起來很亂,但如果你仔細觀察,它會變得很有意義)

這不是用WP 3.0.x測試過的,但它確實做得非常精確你想要什麼。請看看它是否適用於您,並隨時詢問是否有問題或不合理。

<?php if (have_posts()): ?> 
    <?php $year = 0; ?> 
    <?php $month = 0; ?> 
     <ul> 

    <?php while (have_posts()): the_post(); ?> 
     <?php $post_year = substr($post->post_date, 0, 4); ?> 
     <?php $post_month = substr($post->post_date, 5, 2); ?> 
     <?php if(($year != $post_year || $month != $post_month) && $year != 0): ?> 
       </ul> 
      </li> 
     <?php endif; ?> 
     <?php if ($year != $post_year || $month != $post_month): ?> 
      <li> 
       <strong><?php the_time('F Y') ?></strong> 
       <ul> 
     <?php endif; ?> 
        <li> 
         <span><?= mysql2date('j', $post->post_date) ?></span> 
         <?php the_title() ?> 
        </li> 
     <?php $year = $post_year; ?> 
     <?php $month = $post_month; ?> 

    <?php endwhile; ?> 
    </ul> 
     </li> 
    </ul> 
<?php endif; ?> 
+0

這個很漂亮!適用於我的3.0.4安裝。謝謝。 – roflwaffle 2011-01-24 16:49:25