0
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?

0

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>';
1

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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