Forums

[resolved] Conditional sidebars based on Custom Taxonomy & post type (2 posts)

  1. abrewitt
    Member
    Posted 1 year ago #

    scenario

    I have one custom post type: events

    Two custom taxonomies: future events & past events - both displaying posts using single-events.php

    I need a way of having a different sidebar for :

    1.future events
    2.past events

    I need something along these lines:

    If custom post "event" & custom taxonomy "future event" then show sidebar 1

    else

    if custom post type "event" & custom taxonomy "future event" then show sidebar 2

    heres where I am upto with code:

    elseif ( get_post_type() == 'events')     {
    	 if ( function_exists('dynamic_sidebar') ) dynamic_sidebar(1);
    } 
    
    elseif ( get_post_type() == 'events')     {
    	 if ( function_exists('dynamic_sidebar') ) dynamic_sidebar(2); 
    
    }

    Please help?

  2. abrewitt
    Member
    Posted 1 year ago #

    Ok, solved the problem - I needed to use:

    elseif ( get_post_type() == 'events')     {
    	global $post;
    	$event_status = get_the_terms( $post->ID, 'event-status' );
    	if( !empty($event_status) && is_array($event_status) && !empty($event_status[37]) ){
    
    if ( function_exists('dynamic_sidebar') ) dynamic_sidebar(6);   // past event sidebar
    
    	}
    	else{
    
    if ( function_exists('dynamic_sidebar') ) dynamic_sidebar(3);   // future event sidebar
    
    	}
    
    }

Topic Closed

This topic has been closed to new replies.

About this Topic