0

Typically if I wanted to have content based on what page someone was on I could do something like

if (is_page('contact')) {
    #code block here

but what about if what want is based on the category of posts? like if the user wanted to filter event type or by state, for this example, lets say by state. This is the current url

/category/upcoming-events

so not really a "page". I wanted to hide some menus and display others if they visit a specific category.

I found in the WordPress documentation that there is this a function for category, but not really sure how to implement anything in their documentation. https://developer.wordpress.org/reference/functions/is_category/

Perhaps something like

is_category( 'upcoming-events' ) {
    echo '<ul class="state">' . #the rest of the code here . '</ul>';

}

and really since I should not add the code there and use a template perhaps

is_category( 'upcoming-events' ) {
    echo <?php get_template_part('part-template-event-filter'); ?>;

}
1

For category check, the CODE would be:

if( is_category( 'upcoming-events' ) ) {
    get_template_part('part-template-event-filter');
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.