• Resolved nathan12343

    (@nathan12343)


    I’ve got sifr running on my site and I want to be able to apply text replacement to the parents in the menu (of pages). The menu is generated through: wp_list_pages. If I apply the replacement to the parent <li> then that style also gets applied to the children because they are nested in the open <li> I guess.

    Does anyone knoe how I can wrap the only the top level pages in a DIV or SPAN or H2 or any other html tag?

    (or a way of working with SiFR 2 to stop the children from picking up the style)

    thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Great question – did you find an answer for this back then?

    Thread Starter nathan12343

    (@nathan12343)

    This is what I did:

    <ul>
    <?php
        $my_pages = wp_list_pages('title_li=&echo=0&depth=2');
    $top_level_pages = mysql_query("SELECT ID FROM $wpdb->posts WHERE post_parent = '0' AND post_type = 'page' AND post_status = 'publish'");
    $my_pages = str_replace('<a href=', '<span><a href=', $my_pages);
    while ($row = mysql_fetch_assoc($top_level_pages)) {
    	extract($row);
    	$my_pages = str_replace('<li class="page_item page-item-' . $ID. '"><span><a href=', '<li class="page_item page-item-' . $ID. '"><span class="onlyparents"><a href=', $my_pages);
    	$my_pages = str_replace('<li class="page_item page-item-' . $ID. ' current_page_item"><span><a href=', '<li class="page_item page-item-' . $ID. ' current_page_item"><span class="onlyparents"><a href=', $my_pages);
    	$my_pages = str_replace('<li class="page_item page-item-' . $ID. ' current_page_ancestor current_page_parent"><span><a href=', '<li class="page_item page-item-' . $ID. ' current_page_ancestor current_page_parent"><span class="onlyparents"><a href=', $my_pages);
    	$my_pages = str_replace('<li class="page_item page-item-' . $ID. ' current_page_parent"><span><a href=', '<li class="page_item page-item-' . $ID. ' current_page_parent"><span class="onlyparents"><a href=', $my_pages);
    }
    $my_pages = str_replace('</a>', '</a></span>', $my_pages);
    echo $my_pages;
    ?>
    </ul>

    What this did was add a span with a class of “onlyparents” to every top level link. This meant that I could use sifr (or Cufon) for those and keep the rest of them in a normal font and preserving the rest of the classes for each li element. I have no idea if there is a better way of doing it but this did the trick.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wrap only the parent in a span or div’ is closed to new replies.