douzheng5717 2010-04-17 06:44
浏览 24

wordpress上的多个日历仅突出显示特定类别

Does anyone know of how, in wordpress, I could implement many calendars on a site, each only highlighting days that are within a specific category? I am hoping to setup multiple calendars, each tracking all of the events from their own cat.

After researching for a while the best I could find was this thread:

http://wordpress.org/support/topic/266627?replies=11

But it seems to peter out before there is ever a working solution

  • 写回答

1条回答 默认 最新

  • dppfxf909679 2010-04-17 08:42
    关注

    What I have below spits out the days in the current month and links (to the day's archive page) days with posts from a certain category. Just duplicate the code for each cat you want to display. To be usable, you'll have to add some conditional formatting to give it nice calendar rows and probably expand the script to cover multiple/partial months, but this should get you started.

    <?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 output:

    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 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题