SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do I add a css class to top level parents

    Hi there.
    I'm wondering: how do I add an extra css class to all top level parents (meaning mainmenu items) using wp_list_pages function in wordpress 2.8?

    See an HTML output example below (I want to add the bold code):
    <li class="mainitem page-item page-item-30">
    <a href="javascript:void(0);" title="Pages">Pages</a>
    <ul>
    <li class="page-item page-item-40"><a href="link-to-submenu-item1" title="link-title1">Link-desription1</a></li>
    <li class="page-item page-item-41"><a href="link-to-submenu-item2" title="link-title2">Link-desription2</a></li>
    <li class="page-item page-item-42"><a href="link-to-submenu-item3" title="link-title3">Link-desription3</a></li>
    </ul>
    </li>
    <li class="mainitem page-item page-item-50">
    <a href="link-to-contact" title="title-contact">Contact</a>
    </li>
    <li class="mainitem page-item page-item-60">
    <a href="javascript:void(0);" title="Others">Others</a>
    <ul>
    <li class="page-item page-item-70"><a href="link-to-submenu-item1" title="link-title1">Link-desription1</a></li>
    <li class="page-item page-item-71"><a href="link-to-submenu-item2" title="link-title2">Link-desription2</a></li>
    <li class="page-item page-item-72"><a href="link-to-submenu-item3" title="link-title3">Link-desription3</a></li>
    </ul>
    </li>

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Since they are all at the same level why not add the class to the <ul> or <ol> and then reference them using ul.mainitem>li
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    felgall, that selector is worthless for IE unfortunately: http://reference.sitepoint.com/css/childselector
    MySQL v5.1.58
    PHP v5.3.6

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    That selector is only worthless for IE6. IE7 and IE8 support it.

    IE6 users are now few enough to not waste time making sure the page looks perfect for them - as long as it is still usable.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your responses guys!
    Felgall, I understand what you're applying... The problem is that in the next step I want to execute a str_replace. The purpose of assigning this class is that there are supposed to be a divider between all the top level menuitems, which I can acchieve by executing: str_replace('<li class="mainitem', '
    <li><span class="qmdivider qmdividery"></span></li>
    <li class="mainitem', $my_pages);

    (The divider which I want to insert is in bold above!)

    Of course I could assign the divider to all menuitems (toplevel/subs/subssubs etc.), but the submenus would then not display properly ;-(

    There's gotta be some way of doing this, right???! /Daniel


Tags for this Thread

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
  •