WordPress.org

Ready to get started?Download WordPress

Forums

WP Calendar
[resolved] Template shortcodes? (2 posts)

  1. nascent666
    Member
    Posted 2 years ago #

    I see in the instructions that you can add a calendar to a post using the post tag {events_calendar}. However, I was wondering if there is a way to add a calendar to a template page. I tried:

    echo do_shortcode('[events_calendar]');

    This didn't work.

    I'm looking for a way to specify a category depending on a querystring variable. If I pass ?market=NY, I want to be able to display a calendar with only NY events in it. Ideally, it would work be doing the shortcode, as in:

    echo do_shortcode('[events_calendar categories="11"]');

    http://wordpress.org/extend/plugins/wp-calendar/

  2. nascent666
    Member
    Posted 2 years ago #

    I figured it out myself, but I didn't add the attributes to the shortcode itself:

    <?php
    function get_cat_info(){
    	$market = getmarket();  //function that reads querystring
    	$catname = $market."-events";
    	$idObj = get_category_by_slug($catname);
    	$id = $idObj->term_id;
    	return $id;
    };
    
    function events_calendar_func( $atts ){
    	$id = get_cat_info();
    	global $fsCalendar;
    	$content = "{events_calendar; categories=\"$id\";}";
    	return $fsCalendar->hookFilterContent($content);
    };
    add_shortcode( 'events_calendar', 'events_calendar_func' );
    ?>

    Now I can put this in the template page:

    <?php echo do_shortcode('[events_calendar]'); ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic