• Hi,

    How can I change this code so it displays the cild pages in columns?

    <?php
    global $wp_query;
    if( empty($wp_query->post->post_parent) ) {$parent = $wp_query->post->ID;} else {
    $parent = $wp_query->post->post_parent;} ?>
    <?php if(wp_list_pages("title_li=&child_of=$parent&echo=0" )): ?>
    <div id="submenu">
    <ul><?php wp_list_pages("title_li=&child_of=$parent" ); ?></ul>
    </div>
    <?php endif; ?>

    I would also like to keep the fact that the code displays the cild pages of the current page.

    Hope someone can help me out!

    /C

Viewing 10 replies - 1 through 10 (of 10 total)
  • The child page links are already being generated inside a <div> tag. What else do you want?

    Thread Starter cgoertz

    (@cgoertz)

    The child page links are already being generated inside a <div> tag. What else do you want?

    Maybe I wasn’t clear enough. I would like to create columns with the help of PHP so that I can control the number of columns and the width.

    display: inline; can not do this and I don’t want to use CSS Multi-column since it only works in new browser.

    Hope this clarifies things.

    instead of repeating previous suggested solutions, here is a search result:
    https://www.wordimpressed.com/wordpress/how-to-display-wordpress-pages-or-categories-in-2-and-3-columns/

    Thread Starter cgoertz

    (@cgoertz)

    Thank you alchymyth for the link.

    I tried THIS now but with now success.
    I guess i dont need to mention that my PHP skills aren’t that great.

    Let me know if im completely wrong.

    make sure to add the ‘echo=0’ parameter also in this line:

    $pageArray = explode("</li>",wp_list_pages('title_li=&child_of=$parent'));
    Thread Starter cgoertz

    (@cgoertz)

    Thank’s for the reply, but still no dice.

    THIS is the code I got so far.

    the ‘echo=0’ is not in all occurances of ‘wp_list_pages()’ in the code – read my reply again.

    Thread Starter cgoertz

    (@cgoertz)

    Thank you for your reply.

    However I’m unable to get this code working. Been trying out different ways to combine the code but nothing works.

    Alchymyth maybe you could explain a bit more what I need to do and what im missing.

    Thank you for your help!

    I was referring to the ‘echo’ parameter of ‘wp_list_pages()’ in line 12 of the pastebin;
    but also just discovered the use of single quotemarks which do not allow to include variables directly;

    try:

    $pageArray = explode("</li>",wp_list_pages("title_li=&child_of=$parent&echo=0"));

    – or if you use single quote marks, try:

    $pageArray = explode("</li>",wp_list_pages('title_li=&child_of='.$parent.'&echo=0'));

    this is line 12 in https://pastebin.com/8Hv87EuZ which contains the full edited code.

    also added a <?php endif; ?> which was not in the pastebin, but might be in your template somewhere else.

    the code seems to produce odd results if the child pages go more than one level deep; and if there is only one page in the list…

    Thread Starter cgoertz

    (@cgoertz)

    Thanks a lot Alchymyth this works great!

    You are right about it only working one level down. And that it looks a bit strange if you only list one item.

    If I find a solution for this I’ll post it here.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Help display child pages in columns’ is closed to new replies.