How can I add a widget (event list) to specified pages?

I normally work in Joomla and have inherited a WP site to maintain/update. It is using the Calendar plugin by Kieran O’Shea, and comes with a widget to display upcoming events. I’d like to add this widget to a few pages on the site - but not all of them.

Can someone give me simple instructions on how to do this? I don’t see an option on the page to display the widget; and I don’t see an option on the widget to display on only certain pages!

OR can you recommend a different/better calendar plugin that has more flexibility for displaying event modules? Being able to auto port over the existing calendar data to the new one would be ideal.

I’m not sure what version it’s running; where can I find that info? At the bottom there is a link that sais download version 2.9.2, so I know it’s not that one. :slight_smile: It was made within the past year.

You could make a new widget area that’s shown only to certain pages. I don’t have a test site in front of me to know for sure but it ought to be ok.

This will first register a new sidebar and then hook it to the init action. It belongs in your theme’s functions.php file.


  function pasnon_newwidgets_init() {
    register_sidebar(array(
      'name' => 'Calendar',
      'id' => 'calendar-box',
      'description' => 'This widget area is only shown on the Events and News pages.',
      'before_widget' => '<div id="%1$s" class="widgetcontainer %2$s">',
      'after_widget' => '</div>',
      'before_title' => '<h3 class="widgettitle">',
      'after_title' => '</h3>',
    ));
  }


// init these
	add_action('init', 'pasnon_newwidgets_init');


You should now be able to see a new sidebar in your Widgets screen and you can bung your calendar (or indeed anything else) in there. Now you need to place it someplace in your template. If you’re using a general page template then call it like so:


if (is_page('Events') || is_page('News')) {
  if (function_exists('dynamic_sidebar') && is_sidebar_active('calendar-box')) {
    dynamic_sidebar('calendar-box');
  }
}

If you’re using specific template for those pages you don’t need to worry about the first if statement…


  if (function_exists('dynamic_sidebar') && is_sidebar_active('calendar-box')) {
    dynamic_sidebar('calendar-box');
  }

Does this help?

…anybody?