wordpress上的多个日历仅突出显示特定类别
问题描述:
有人知道在wordpress中,我可以在网站上实现多个日历,每个日历只突出显示特定类别内的日子吗?我希望能够设置多个日历,每个日历都会跟踪他们自己猫的所有事件。wordpress上的多个日历仅突出显示特定类别
研究了一段时间后,我能找到的最好的是这个线程:
http://wordpress.org/support/topic/266627?replies=11
但似乎逐渐消失之前有过一个可行的解决方案
答
我有以下吐出来当前月份的日期以及来自某个类别的帖子的链接(到当天的归档页面)。只需复制你想要显示的每只猫的代码。为了可用,你必须添加一些条件格式来给它很好的日历行,并可能扩展脚本以涵盖多个/部分月份,但这应该让你开始。
<?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