WordPress.org

Ready to get started?Download WordPress

Forums

Calendar widget - how to display posts from specific category only? (12 posts)

  1. krko
    Member
    Posted 4 years ago #

    Hello,

    I'm using wordpress 2.9.1 with arthemia theme and calendar widget enabled in sidebar. I'd like the calendar widget to show posts only from a certain category (let's say events) so basically it functions as events calendar. Currently the calendar displays posts from all categories.
    I'm rather new to wordpress and I'd appreciate any help on this subject. I tried searching for the solution, however haven't found anything.

    Thank you,
    krko

  2. krko
    Member
    Posted 4 years ago #

    bump

  3. MichaelH
    Member
    Posted 4 years ago #

    Not sure about it relates to the plugin, but you could put this in your sidebar template, or consider downloading and installing Otto's PHP Code Widget and using the code in one of those widgets:

    <?php
    //display all posts for category 5
        $args=array(
          'cat' => 5,
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of Posts';
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
          endwhile;
        }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  4. krko
    Member
    Posted 4 years ago #

    Hi Michael,

    Thank you for your answer.
    I'm using the default wp calendar widget. This is the code from default-widgets.php:

    /**
     * Calendar widget class
     *
     * @since 2.8.0
     */
    class WP_Widget_Calendar extends WP_Widget {
    
    	function WP_Widget_Calendar() {
    		$widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your blog’s posts') );
    		$this->WP_Widget('calendar', __('Calendar'), $widget_ops);
    	}
    
    	function widget( $args, $instance ) {
    		extract($args);
    		$title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title']);
    		echo $before_widget;
    		if ( $title )
    			echo $before_title . $title . $after_title;
    		echo '<div id="calendar_wrap">';
    		get_calendar();
    		echo '</div>';
    		echo $after_widget;
    	}
    
    	function update( $new_instance, $old_instance ) {
    		$instance = $old_instance;
    		$instance['title'] = strip_tags($new_instance['title']);
    
    		return $instance;
    	}
    
    	function form( $instance ) {
    		$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
    		$title = strip_tags($instance['title']);
    ?>
    		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
    		<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>

    What should I change in there so it displays only posts from category X?

    Thank you.

    Goran

  5. MichaelH
    Member
    Posted 4 years ago #

    Have you looked at a plugin instead? Here's one: http://wordpress.org/extend/plugins/calendar/

  6. krko
    Member
    Posted 4 years ago #

    Hi Michael,

    Thank you once again for your help. I know that plugin however it doesn't suit my needs. It doesn't support non-latin characters (which I have to use in my website) so unfortunately it's a no on this one. I'd much rather use the default calendar widget and make it display posts only from a specific gallery.

    Can anyone point me in the right direction?

    Thank you in advance.

    krko

  7. jportiz
    Member
    Posted 4 years ago #

    Hi krko!!!

    Im having the same trouble as you are... if you found a way to solve it please let me know!!! either via this forum or twitter: ortizjp or email: jp.ortizn@gmail.com

    thanks!

  8. Kieran O'Shea
    Member
    Posted 4 years ago #

    krko, non latin character support was added in the development version

  9. GandJ
    Member
    Posted 4 years ago #

    hey guys, is any one found the solution to display the default calendar widget only for a specific category posts?

  10. musik
    Member
    Posted 4 years ago #

    I'd be interested in this answer too. I just want to use one category to display in the default calendar option.

  11. Zac
    Member
    Posted 4 years ago #

    Another vote for very interested in the answer.

  12. nick ellison
    Member
    Posted 4 years ago #

    if you want an events calendar, I came across this post......http://www.davidrisley.com/2010/04/23/events-list-with-wordpress/

    Read the description, its exactly what I need, however I have no idea where to put the script that has been created? If it makes sense to anyone else please let me know!!!!!

Topic Closed

This topic has been closed to new replies.

About this Topic