How to use internal WP functions for custom menu items
-
I have an overall question about how others build custom menu’s in WordPress and add an “id=current” action to it. Because I have the idea that the way I do it, is not the best one. (To use an understatement) There must be a much better way.
It’s a bit hard to explain.
What I mean is that Worpdress can render it’s own menu’s with the help of <?php wp_list_pages( $args ); ?> or <?php wp_nav_menu( $args ); ?>
And when doing so, it can add a ‘current id’ tag to the concerning<li>
tag in the menu.
So far so good.My problem is that a lot of times I can’t use the WordPress internal function because every seperate
<li>
of the menu needs to be styled apart/unique (e.g. due to a unique background color, or a unique button width)
Example.
I can have a menu like this:HTML
<ul id="navigation"> <li class="button1"><a>Button1</a></li> <li class="button2"><a>Button2</a> <li class="button2"><a>Button2A</a></li> <li class="button2"><a>Button2B</a></li> </li> <li class="button3"><a>Button3</a></li> <li class="button4"><a>Button4</a></li> </ul>
CSS
ul#navigation { padding: 0; list-style-type: none; position: relative; } #navigation li { display: block; float: left; } #navigation li.button1 { width: 135px; background-color: #284; } #navigation li.button2 { width: 120px; background-color: #f30; } #navigation li.button3 { width: 131px; background-color: #61a; } #navigation li.button4 { width: 145px; background-color: #d3e; }
Usually I end up NOT using the internal WP functions, hard-coding this construction in the template. And of course this comes with the expected problems like:
– No flexibility in the menu (changing a page means changing the template)
– No automagical “currentpage-ID”My question is more simple than the explanation ??
How do others solve this. It would be great to use the wp_list_pages or wp_nav_menu anyway. This would solve the “current page ID” problem at the same time.
If not possible, is there a way to create an ‘current page ID’ function anyway? (I mean, without using self made scripts)[Moderator Note: Please post code or markup snippets between backticks or use the code button.]
- The topic ‘How to use internal WP functions for custom menu items’ is closed to new replies.