1

I am creating a dynamic menu and in my foreach loop I am running a is_page using the page title:

<li class="<?= (is_page($tlp->post_title) ? 'active' : '');?>">
</li>

This works fine for pages that are actually created in the WP admin. But for other post types that rely on the archive it doesn't work.

So I have a 'team' post type and a archive-team.php page which uses the data.

When on that page, I have no way of checking if the page is currently active?

I came across is_archive() but that doesn't do as expected. Just returns if it is a archive.

I also loop through the pages to create this menu, so I have a blog page set up and just do a check in the default template to include the archive if its the blog page.

Any help?

1
  • This won't fix your issue, but you should pass the ID instead of the title: is_page( $tlp->ID ) Nov 3, 2015 at 15:47

1 Answer 1

1

You can use is_page( $tpl->ID ) || is_single( $tlp->ID ) which will cover posts, pages and custom post types.

For the archive link, use is_post_type_archive( $post_type ). If you need it highlighted for single posts of the same type, add || is_singular( $post_type )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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