2010-04-17 130 views

回答

0

我有以下吐出来当前月份的日期以及来自某个类别的帖子的链接(到当天的归档页面)。只需复制你想要显示的每只猫的代码。为了可用,你必须添加一些条件格式来给它很好的日历行,并可能扩展脚本以涵盖多个/部分月份,但这应该让你开始。

<?php 

$today = getdate(); 
query_posts('category_name=mycat' . '&year=' . $today["year"] . '&monthnum=' . $today["mon"]); // query_posts() is a WP function 

if (have_posts()) 
{ 
    $postDates = array(); 
    while (have_posts()) 
    { 
     // The if/while we're in now is called the "WordPress Loop" 

     the_post(); // Sets all the WP variables up for the current post 
     $postDates[] = (int)(the_date("j", "", "", FALSE)); // the_date() is a WP function 
    } 

    for ($i = 1; checkdate ((int)(date("n")), $i, (int)(date("Y"))); $i++) 
    { 
     // checkdate() is a PHP function which validates a date against the gregorian calendar 
     if (in_array($i, $postDates)) 
     { 
      echo "<a href=\"" . get_day_link('','',$i) . "\">" . $i . "</a> "; // get_day_link() is a WP archive function 
     } 
     else 
     { 
      echo $i . " "; 
     } 
    } 
} 

wp_reset_query(); // Resets the WP variables so everything's back to normal 

?> 

HTML输出:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <a href="http://www.myblog.com/2010/04/17/">17</a> 18 19 20 21 22 23 24 25 26 27 28 29 30