SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Custom menu style problem

    Hi,



    I am using a wordpress theme with a custom top navigation menu 'wp_list_pages2()'. This custom naviagtion menu adds a 'select' class to the current menu item. Like below:

    <div id="menu">
    <ul>
    <li>|</li><li><a class="select" href="http://www.ljwg.org.uk/"><span>Home</span></a></li><li>|</li><li><a href="http://www.ljwg.org.uk/?page_id=18"><span>About us</span></a></li><li>|</li><li><a href="http://www.ljwg.org.uk/?page_id=21"><span>Events</span></a></li><li>|</li><li><a href="http://www.ljwg.org.uk/?page_id=26"><span>Media</span></a></li><li>|</li><li><a href="http://www.ljwg.org.uk/?page_id=101"><span>Contact</span></a></li> </ul>

    </div>



    The problem is that this class is only added to menu links for static pages. When on the blog page (media) the class does not appear for the menu item.

    <div id="menu">
    <ul>
    <li>|</li><li><a href="http://www.ljwg.org.uk/"><span>Home</span></a></li><li>|</li><li><a href="http://www.ljwg.org.uk/?page_id=18"><span>About us</span></a></li><li>|</li><li><a href="http://www.ljwg.org.uk/?page_id=21"><span>Events</span></a></li><li>|</li><li><a href="http://www.ljwg.org.uk/?page_id=26"><span>Media</span></a></li><li>|</li><li><a href="http://www.ljwg.org.uk/?page_id=101"><span>Contact</span></a></li> </ul>

    </div>

    the php for this menu is as follows:

    function wp_list_pages2() {

    $defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_option('date_format'),
    'child_of' => 0, 'exclude' => '', 'title_li' =>'', 'echo' => 1, 'authors' => '', 'sort_column' => 'menu_order, post_title');
    $r = array_merge((array)$defaults, (array)$r);

    $output = '';
    $current_page = 0;

    // sanitize, mostly to keep spaces out
    $r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']);

    // Allow plugins to filter an array of excluded pages
    $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));

    // Query pages.
    $pages = get_pages($r);

    if ( !empty($pages) ) {

    for($i=0;$i<count($pages);$i++)
    {
    $class='';
    if(is_page($pages[$i]->post_title))
    $class=' class="select" ';
    $output .='<li>|</li><li><a '.$class.' href="'.get_page_link($pages[$i]->ID).'"><span>'.$pages[$i]->post_title.'</span></a></li>';

    }
    }

    $output = apply_filters('wp_list_pages', $output);

    echo $output;
    }


    I used simpe CSS to style the current page item:

    #menu li a.select{
    font-weight: bold;
    }

    Does anyone have any idea why this would be.

    Cheers

  2. #2
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe because those pages are not quite pages, but category pages or archives?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •