Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
wp_list_pages('title_li=&depth=&exclude='); 

lists all pages of my site. If there are childpages of a certain page the output looks like this:

<li class="page_item page-item-2">
    <a href="http://domain.com/about" title="About">About</a>
    <ul class="children">
        <li class="page_item page-item-29">
            <a href="http://domain.com/about/subpage" title="Subpage">Subpage</a>
            <ul class="children">
                <li class="page_item page-item-39"><a href="http://domain.com/about/subpage/subsub" title="SubSub">SubSub</a></li>
            </ul>
        </li>
    </ul>
</li>

Is there a simple trick to print childpages without seperate 's so that the output looks like this:

<li class="page_item page-item-2">
    <a href="http://domain.com/about" title="About">About</a>
</li>
<li class="page_item page-item-29">
    <a href="http://domain.com/about/subpage" title="Subpage">Subpage</a>
</li>
<li class="page_item page-item-39"><a href="http://domain.com/about/subpage/subsub" title="SubSub">SubSub</a>
</li>

I need that version just for a specific part of my page so it shouldn't be a filter that is added to wp_list_pages().

Any idea how to accomplish that?

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

you can use get_pages() function, something like this:

$mypages = get_pages();
echo '<ul>';
foreach($mypages as $page){     
    echo '<li class="page_item page-item-'.$page->ID.'"><a href="'.get_page_link($page->ID).'">'.$page->post_title.'</a></li>';
}
echo '</ul>';
share|improve this answer
    
perfect thank you! –  mathiregister Mar 28 '11 at 19:22
add comment

Actually, I believe that passing depth=-1 to wp_list_pages() should list all pages as a flat, non-nested list. It won't preserve the order of sub-pages, though, so you're not guaranteed that "Subpage" will immediately follow "About" in your example... Everything will be ordered by the field selected in the sort_column parameter.

share|improve this answer
    
Indeed you are correct! I had forgotten about that. codex.wordpress.org/Function_Reference/wp_list_pages –  Chip Bennett Mar 28 '11 at 19:22
add comment

Not by default. wp_list_pages() does not have a "hierarchical" argument. It will always output Pages as hierarchical.

You could modify the CSS, such that the child ULs and LIs appear identical to the parent ULs/LIs, but the pages will still be listed hierarchically.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.