WordPress.org

Support

Support » Plugins and Hacks » Can the default calendar be set to display posts from only one category?

Can the default calendar be set to display posts from only one category?

  • Hey there wp forum…

    I’m looking to use the default wp Calendar widget, but I’d like the calendar to only display posts from one specific category, and ignore all of the others.

    For example, let’s say I have two categories, “Dates” and “News”. When I post something under “News”, I’d like the calendar to not display a link on the day of that news post. Yet, if another day I post under “Dates”, I want the calendar to provide a link to that post on the day it was posted.

    Any help anybody? Thanks ahead of time….

    P.S. I’m using a customized theme, but the calendar seems untouched…

Viewing 6 replies - 1 through 6 (of 6 total)
  • also interested +1

    – did you find a solution nullsett?

    It’s a little bit of work, but you can do it.

    1. Open up (or create if it doesn’t exist) the functions.php file in your theme folder
    2. Write a function to output your stylized calendar. What I did was to copy and modify the wp_widget_calendar() and get_calendar() functions out of /wp-includes/widgets.php
    3. Register your function as a replacement for the default calendar with the following: wp_register_sidebar_widget('calendar', __('Calendar'), 'your_custom_calendar_callback');

    The key with this method is to tweak the SQL queries in the get_calendar() function so that they return only posts from the category you’re interested in.

    HTH

    I don’t know PHP, but I really need a single category calendar, so I’m going to take a shot at creating a new calendar function.

    I found the get_calendar function in wp-includes/general-template.php Can anyone help me with the MySQL call for getting a single category? I’m having trouble wrapping my head around the new taxonomy system…

    I modified Ajax Calendar to display a single category. I changed calendar.php (inside the models folder) adding some code around line 174 to check if the post is in the events category.

    I took this:

    WHERE MONTH(post_date) = $thismonth
    AND YEAR(post_date) = $thisyear
    AND post_status = 'publish' AND post_type='post'
    ", ARRAY_N);

    Added a line to check for category 5:

    WHERE MONTH(post_date) = $thismonth
    AND YEAR(post_date) = $thisyear
    AND post_status = 'publish' AND post_type='post'
    AND wp_term_taxonomy.term_id IN (5)
    ", ARRAY_N);

    It’s working fine so far, but any advice would be appreciated.

    Hi,

    I’d like to add a line where I select the categories of posts I want to diplay on calendar:

    this is my code:

    FROM $wpdb->posts WHERE MONTH(post_date) = $thismonth
      		AND YEAR(post_date) = $thisyear
      		AND post_status = 'publish' AND post_type='post'
    		AND post_date <> '" . current_time('mysql') . '\'', ARRAY_N);

    Thank you!

    Hi,

    I’m still looking for a solution for this. I want the default calendar (or another one) to only display posts from specific categories.

    Thanks…

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Can the default calendar be set to display posts from only one category?’ is closed to new replies.
Skip to toolbar