slobjones Posted February 2, 2012 Share Posted February 2, 2012 This topic combines WordPress conditional statements with PHP. Hoping to get some help here. I'd like to create a dynamic WordPress menu with a mix of static pages and custom post type archives that applies a class of "current" to the current tab. The example below uses 1) Static page set as Home 2) Static page 3) Custom post type archive 4) Static page for blog content. Tried to edit the code from my previous menu, but it's not working (see below). I'd appreciate any assistance! Thanks. <ul> <li<?php if ( is_front_page() ) { echo ' class="current"'; } ?>><a href="/">Home</a></li> <li<?php if ( is_page('my-page') { echo ' class="current"'; } ?>><a href="/my-page/">My Page</a></li> <li<?php if ( is_post_type_archive('my-custom') && is_single()) { echo ' class="current"'; } ?>><a href="/my-custom/">My Custom Posts</a></li> <li<?php if ( is_page('blog') { echo ' class="current"'; } ?>><a href="/blog/">Blog</a> </li> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/256228-wordpress-dynamic-menu-with-custom-post-types/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.