Note: The following knowledge base article and associated code snippet will only work with Timeline Express Pro v1.2 or later.

Timeline Express Pro users have the ability to assign announcements to multiple timelines, as well as assign any number of categories to an announcement.

Some users may want to display those categories on the timeline or the single announcement template. Out of the box, the categories are not visible – but by hooking a single function into two actions provided by Timeline Express, we can display our assigned categories.

The following snippet is going to query the assigned categories for a given announcement, and then display it below the announcement title on both the single announcement page and on the timeline itself.

Note: This code snippet should be placed in the functions.php file of your active theme, or child theme.

/**
 * Display the associated categories for the specified announcement
 * @return string 
element with our terms separated by a comma */ function display_timeline_categories() { global $post; // retreive associated categories on this announcement $terms = wp_get_post_terms( $post->ID, 'timeline_express_categories' ); $term_array = array(); foreach ( $terms as $term ) { $term_array[] = $term->name; } echo '
' . implode( ', ', $term_array ) . '
'; } add_action( 'timeline-express-after-title', 'display_timeline_categories' ); add_action( 'timeline-express-single-before-image', 'display_timeline_categories' );

If you want the image to only display in the timeline container, simply comment out or remove add_action( 'timeline-express-after-title', 'display_timeline_categories' );. If you only want the categories to display on the single announcement template you can comment out add_action( 'timeline-express-single-before-image', 'display_timeline_categories' );.

When used in conjunction with one another, you can quickly and easily display the assigned announcement categories on any part of the plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.