SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating Sequential Count on Wordpress Nav Menu

    Hi,
    I have a piece of code which I'm using to add a sequential number to each item in a list. The reason for this is because the graphic designer for the project wants a different background item for everything in the list, and doing this works perfectly for me. However, a problem has arisen as the code was being used for just a one-level list. Now, it's got two levels but I don't want the child list items to be included in the count. Does anyone know how I could change this code so that it only counts items in the parent list?

    Here's my code at the moment:

    PHP Code:
                $navcount wp_nav_menu( array(
                                    
    'theme_location' => 'Top Bar',
                                    
    'menu' => 'Main Menu',
                                    
    'depth'      => 2,
                                    
    'container'  => false,
                                    
    'echo'            => false,
                                    
    'menu_class'     => 'nav'
                                
    ) ); 

                
    $nav_bits explode('<li '$navcount);
                
    $navcount ''$i 0;
                foreach(
    $nav_bits as $bits) :
                if(
    $i==0) { $navcount $navcount.$bits; }
                else { 
    $navcount $navcount.'<li class="item'.$i.'" '.$bits; }
                
    $i++;
                endforeach;
                echo 
    $navcount
    Thanks!
    Russ

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,200
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    I don't know WP code at all, but I wonder if you've played with those settings at all, such as changing

    Code:
    'depth'      => 2,
    to

    Code:
    'depth'      => 1,
    If all else fails, you can do this with CSS.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    I don't know WP code at all, but I wonder if you've played with those settings at all, such as changing

    Code:
    'depth'      => 2,
    to

    Code:
    'depth'      => 1,
    If all else fails, you can do this with CSS.
    Hey Ralph,
    I have played around with it, but with no luck. Changing the depth to 1 means that it kind of does what I want it to do, but I then lose all the child menus in the final code. If I was to do it that way I would need to use the code to append the ID to the menu and then run the code again with a depth of 2 but including the extra code I'd just generated, but I really don't know how to do that.

    How would you do this with CSS?

    Cheers,
    Russ

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,200
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by slaterino View Post
    How would you do this with CSS?
    You would just allow a background image on top level links but not on lower level ones. If you've able to post a live link we can give you the exact code.


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
  •