• Resolved tkien

    (@tkien)


    Hi,

    I have just used WP, I have question about menu. I created tab menu from categories. When I read an article from category A for instance, the category A on the menu doesnt highlight. How do I make it works? I want the category on the menu also show up too.

    CSS:

    #nav {margin: 0; padding: 0; list-style: none; float: left;	font-family: Geneva, Arial, Helvetica, sans-serif;}
    #nav li {display: block;float: left;margin-left: 4px;padding: 7px 14px 7px;border-top: 1px solid #fff;	text-transform: uppercase;	font-size: 14px;font-weight: bold;background: #e7eaea url(images/tab_bg.gif) bottom left repeat-x;}
    #nav li:first-child {margin-left: 1px;}
    #nav li a {color: #555;text-decoration:none;}
    #nav li.current-page {background: #FFF;}
    #nav li.current-page:first-child {margin-left: 0;}
    #nav li.current-page a,
    #nav li.current-page a:hover {color: #0072ff;}
    #nav li a:hover {text-decoration: none;color: #222;}
    #nav li.current-cat {background: #FFF;}
    #nav li.current-cat:first-child {margin-left: 0;}
    #nav li.current-cat a,
    #nav li.current-cat a:hover {color: #0072ff;}

    Code on header.php

    <ul id="nav">
    	<li<?php if(!is_category() &amp;&amp; !is_page() &amp;&amp; !is_single()) { ?> class="current-page"<?php } ?>><a href="<?php bloginfo('url'); ?>" title="Home">Home</a></li>
    	<?php wp_list_categories('orderby=ID&amp;order=ASC&amp;depth=1&amp;hide_empty=0&amp;title_li='); ?>
    </ul>

    thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Home highlights because when it is selected it is marked as the current page:

    if(!is_category() &amp;&amp; !is_page() &amp;&amp; !is_single()) { ?> class="current-page"<?php } ?>

    NB. It would be nicer to change that to <?php if(is_home()) echo ' class="current-page" '; ?>

    At the moment you can’t highlight a category that is selected using wp_list_categories(). The only way of getting round it would be to manually insert each category – for example:

    <li<?php if(is_category('Xcategory nameX')) echo " class=\"current-page\"?>><a href="<?php bloginfo('siteurl'); ?>Xcategory linkX">Xcategory nameX</a></li>

    There may be other scripts and/or plugins out there that will do this without the hassle, but that’s the basic fix.

    Thread Starter tkien

    (@tkien)

    Thank you ?? I found a way to reslove it. Use this code

    <?php
    if  (!is_page() &amp;&amp; !is_home()){
    	$catsy = get_the_category();
    	$myCat = $catsy[0]->cat_ID;
    	$currentcategory = '&amp;current_category='.$myCat;
    }
    wp_list_categories('hierarchical=1&amp;use_desc_for_title=0&amp;exclude=12&amp;depth=1&amp;orderby=id&amp;title_li='.$currentcategory);
    ?>

    https://www.ads-software.com/support/topic/211637

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘navigation menu question’ is closed to new replies.