tags:

views:

37

answers:

1

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

A: 

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/"&gt;17&lt;/a&gt; 18 19 20 21 22 23 24 25 26 27 28 29 30 
cowbellemoo