Template Functions

The MegaCalendar plugin exposes a number of functions for use in your custom theme, they are outlined below.

megacal_events

This function loads the calendar/list view into the template where the function is called. This is functionally the same as using the megacal shortcode.

Params:

  • Array $args: An array of shortcode arguments – All valid shortcode options are valid args for this function.

Examples:

// Load a MegaCalendar instance with default options
megacal_events();

// Load a MegaCalendar instance with dark theme, and category filters enabled
megacal_events( array( 
    'theme' => 'dark',
    'showfilters' => true,
) );

megacal_get_default_event_image_path

This function is used to get the path to our default event image, when an event does not have an image available.

NOTE: This function is used only to get the path, if you need to change the default image. Use the megacal_default_event_image_path filter hook.

Examples:

// Output the default event image
<image src="<?php echo megacal_get_default_event_image_path(); ?>" alt="My Event" />

megacal_is_event_detail

This function will return true any time you are on an Event Detail page. This is useful if you are trying to add theme logic that should run only on specific pages.

Examples:

// ...header.php...
// Load a special nav menu on Event Detail
if( megacal_is_event_detail() ) {

     wp_nav_menu( array(
        'theme_location' => 'events',
        'menu_id' => 'event-menu',
    ) ); 

} else {

    wp_nav_menu( array(
        'theme_location' => 'top',
        'menu_id' => 'top-menu',
    ) ); 

}

get_default_megacal_args

This function returns an array with our default shortcode arguments. This function is mainly used internally, but it is available if you need it.

NOTE: You do not need to pass these args to megacal_events(), they are automatically applied there.

Examples:

// Loop through all default args and echo them to the page
$args = get_default_megacal_args();
foreach( $args as $key => $val ) {
    echo $key . ' => ' . $val;
}

megacal_get_template_part

This function attempts to find a specific template part in your theme, inside of the megabase-calendar directory. If the file is not found in the theme, it checks the plugin as a fallback. This is mainly used internally, but you could use it in order to create a custom template stored in the same place as any template overrides that you have.

The fallback order is Child Theme > Parent Theme > MegaCalendar Plugin.

Params:

  • String $slug The prefix slug for the template part – This is the path, inside of the megabase-calendar directory, up to the first hyphen in the template filename
  • String $name The remainder of the filename after the first hyphen – May be left out if your filename is a single word

Examples:

// Render a custom template part
// wp-content/themes/my-theme/megabase-calendar/views/custom-template-part.php
megacal_get_template_part( 'views/custom', 'template-part' );

// wp-content/themes/my-theme/megabase-calendar/views/partial.php 
megacal_get_template_part( 'views/partial' );

// wp-content/themes/my-theme/megabase-calendar/part-custom-list.php 
megacal_get_template_part( 'part', 'custom-list' );