• stardog

    (@stardog)


    Lets say I use something like to display my pages:

    <?php wp_list_pages(); ?>

    That codes creates all this:

    <li class="pagenav">Pages<ul><li class="page_item"><a href="pagename" title="Page Name">Page Name</a></li></ul></li>

    Is it FORCING me to add those classes to my stylesheet and use those instead of my own?

    I don’t even want the pages I have to be put into a list either. How do I control it without changing all the files outside my template’s directory?

Viewing 4 replies - 1 through 4 (of 4 total)
  • drmike

    (@drmike)

    You may want to review the codex page as you can set options for that template tag.

    Template_Tags/wp_link_pages

    Hope this helps,
    -drmike

    Root

    (@root)

    And if absolutely necessary (which it is sometimes to get rid of markup) you can edit the function itself.

    Server borked, created a double post. The next one is the one I intended to post….

    I don’t get why the wp_list_pages function is contained in LI tags at all….that is totally non-standard code. Unless you are ALWAYS going to nest it inside another list, I can’t imagine why this would be hard coded into the WP core.

    But as Root said, it can be changed by editing the function itself. Here are instructions for 2.1.3. Other versions are probably similar. Don’t forget to make a back up before you do this!!!

    You’ll be changing this file:

    /wp-includes/post_functions.php.

    Locate “function wp_list_pages” (line 265 in my 2.1.3)

    Look for the “if” statement and remove the opening and closing LI tags in the two lines ?output= (one of them includes class=pagenav), so it reads as follows:

    if ( !empty($pages) ) {
    		if ( $r['title_li'] )
    			$output .= '' . $r['title_li'] . '<ul>';
    
    		global $wp_query;
    		if ( is_page() )
    			$current_page = $wp_query->get_queried_object_id();
    		$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
    
    		if ( $r['title_li'] )
    			$output .= '</ul>';
    	}

    When looking at the whole function, you’ll see you can also remove the page_item class for the inner nested LIs if you want, but you can also just not define that class in CSS and it won’t do anything.

    I have been battling this weird nesting problem for ages, and this thread finally led me to the solution, so I thought it might help someone else down the road to have it posted in detail.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WordPress using its own classes?’ is closed to new replies.