View Full Version : WordPress dynamic menu with custom post types

02-02-2012, 05:27 AM
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!


<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>