wordpress menu problems with custom templates

I am assuming if you found this post you were using google!

ANYWAYS! The problem I was having on one of my sites was that the css implementation with my theme was no longer working.  Specifically I was using custom templates for certain pages and when I was on one of those pages the link to that page in the navigation menu would not be highlighted.  So usually wordpress takes care of this functionality with a css class called-> ‘.current_page_item’

A lot of times in themes you will see an implementation like this!

This would make the current page item white, so in my case when you click the ‘About’ Page you would get all your links as red except the current page, ‘About’ which would be in white.  This is awesome for user experience because not only do they see the title usually in h1 or h2 format as ‘ABOUT!’ they will see the about link formatted the way you want (in this case bright white!)

My problem was that if you use custom templates this can easily upset the normal wordpress functions.  I solved this problem by using a simple php that grabbed the address bar to see what page you were on since the function is_page(), is_home() and is_front_page() also do not work when using custom templates (not always, i see it work sometimes, but it is easier to fix it this way then dive into every theme and implementation.

When I grab the address bar I do a ‘if’ statement to check what page I am in, then throw a div tag so I can format the link appropriately.  In my case my code looks like this->

<?php if($_SERVER['REQUEST_URI']==”/2.0/blog/”) echo “<div id=’sean_override2?>”; ?>
<?php if($_SERVER['REQUEST_URI']==”/2.0/videos/”) echo “<div id=’sean_override_videos’>”; ?>
<?php wp_list_pages(‘title_li=&sort_column=menu_order&exclude=’.get_option(‘tbf2_exclude_pages’)); ?>
<?php if($_SERVER['REQUEST_URI']==”/2.0/blog/”) echo “</div>”; ?>
<?php if($_SERVER['REQUEST_URI']==”/2.0/videos/”) echo “</div>”; ?>

My css is as follows, but obviously this will be very different depending on what you are doing.

So I threw a div id tag when I was on my video page (which has id-24) so then I can over-ride any problems with the div tags and force it to white despite the is_wordpress functions failing.  YAY!  You can check out my implementation on http://www.capsoffplease.com/2.0

The video page on that page is throwing out some custom code to only grab the posts with the category tag ‘videos’ and this messed up the built in ‘current_page_item’.  My implementation does not only work awesomely, but does not slow my server down at all because it is only adding one conditional statement.  YAY!  If you found this post drop me a line, I like seeing where people come from!

2 Replies to “wordpress menu problems with custom templates”

Leave a Reply to Jason Cancel reply

Your email address will not be published. Required fields are marked *

*