Idea (need PHP-Developer to make it real): Dynamic Category Menu Highlighting
-
Hello,
while talking to about using wordpress as a cms today, me and a colleque came up with an idea about THE problematic part when using WP as a simple CMS.
* the problem (or better task) *
Creating a dynamic sidebar menue from the categories with menu highlighting.
In detail: the menu in the sidebar should be generated with a normal list (formatted by CSS ?? from the wordpress-categories. When browsing a certain category this categors should be highlighted by using an id like “current”* Idea *
While reading the WordPress Codex about dynamic menu highlighting (https://codex.www.ads-software.com/Dynamic_Menu_Highlighting) I came up with a (static) solution:
<ul>
<li<?php if (is_page('CATEGORY1')) { echo " id=\"current\">"; ?> <?php } ?> <a href="/CATEGORY1/">CATEGORY1</a></li>
<li<?php if (is_page('CATEGORY2')) { echo " id=\"current\">"; ?> <?php } ?> <a href="/CATEGORY2/">CATEGORY2</a></li>
[...]
</ul>Unfortunately I need to make changes in the templates, not much work but still not very nice for a non-wordpress-experienced user.
What I want is a plugin or a piece of PHP-code that will create this list for me by using the category names (to make it easier I call this thing ‘GetCategoriesForMenu’):
GetCategoriesForMenu (sublevels=0)
sublevels=0 -> Only the main categories
sublevels=1 -> take main category and the first children categories.The function then creates a list like above, in case of children it creates a nested list and put the parent category in front of the path.
CATEGORY1
CATEGORY1.1
CATEGORY1.2
CATEGORY2should render to:
<ul>
<li<?php if (is_page('CATEGORY1')) { echo " id=\"current\">"; ?> <?php } ?> <a href="/CATEGORY1/">CATEGORY1</a></li>
<ul>
<li<?php if (is_page('CATEGORY1.1')) { echo " id=\"current\">"; ?> <?php } ?> <a href=CATEGORY1/CATEGORY1.1/">CATEGORY1.1</a></li>
<li<?php if (is_page('CATEGORY1.2')) { echo " id=\"current\">"; ?> <?php } ?> <a href=CATEGORY1/CATEGORY1.2/">CATEGORY1.2</a></li>
</ul>
<li<?php if (is_page('CATEGORY2')) { echo " id=\"current\">"; ?> <?php } ?> <a href="/CATEGORY2/">CATEGORY2</a></li>
</li>sounds complicated, I hope you understand what I mean ??
Is anybody capable of written such a plugin, I think its not to hard to get a list of the category-names and create a list of it.
Any PHP-experts out here? Maybe you get motivated when I promise to send you something from your amazon-wishlist ??
I think this pluging would be really enhance wordpress and make it much more easier to use it as a full CMS, what do you think?
Best regards from Berlin / germany
P hil
- The topic ‘Idea (need PHP-Developer to make it real): Dynamic Category Menu Highlighting’ is closed to new replies.