• zonetrap

    (@zonetrap)


    I have a sidebar that changes depending on the page I’m on. If the parent page is Fruit and Oranges and Apples are subpages, then the sidebar will show:
    Fruit
    -Apples
    -Oranges

    But if the PArent Page doesnt have any children, a blank box shows up. I was wondering if there was a way to always have the parent page header in there?

    Here is the code:

    <li class="sidebox">
    
    <?php /* Creates a menu for pages beneath the level of the current page */
    if (is_page() and ($notfound != '1')) {
    $current_page = $post->ID;
    while($current_page) {
    $page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
    $current_page = $page_query->post_parent;
    }
    $parent_id = $page_query->ID;
    $parent_title = $page_query->post_title;
    
    if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status != 'attachment'")) { ?>
    
    <div class="sb-pagemenu"><h2><?php echo $parent_title; ?> Subpages</h2>
    
    <ul><?php wp_list_pages('sort_column=menu_order&title_li=&child_of='. $parent_id); ?></ul>
    <?php if ($parent_id != $post->ID) { ?>
    -Back to <a>" ><?php echo $parent_title; ?></a>
    <?php } ?>
    </div>
    <?php } } ?>

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter zonetrap

    (@zonetrap)

    No one?

    metialb

    (@metialb)

    do you have a link of your blog?

    Thread Starter zonetrap

    (@zonetrap)

    Thread Starter zonetrap

    (@zonetrap)

    Any luck with this?

    Thread Starter zonetrap

    (@zonetrap)

    bumping it.

    Thread Starter zonetrap

    (@zonetrap)

    OK,
    I got some leads, someone told me I should try inserting a count on subpages, and then, if the subpages = 0, then the <div></div> doesnt show up or just keeps the parent page as the header.

    Can anyone help me out and work the code in?

    peiqinglong

    (@peiqinglong)

    In this last line:

    <?php } } ?> change it to reflect <?php } else {} } ?> and see if that works.

    peiqinglong

    (@peiqinglong)

    I’m sorry…actually I noticed what the problem might be. At the very beginning you have: <li class="sidebox">, remove that.

    In the code: <ul><?php wp_list_pages('sort_column=menu_order&title_li=&child_of='. $parent_id); ?></ul>, this line will call an unordered list if there are subpages. You might have to change that to <ul=”sidebox”> or something so it looks the same as your website.

    Thread Starter zonetrap

    (@zonetrap)

    peiqinglong,
    You my friend, helped me out big time! And it was so easy. Thanks a million, and if I can help you with anything let me know. Free t-shirt?

    peiqinglong

    (@peiqinglong)

    LOL, you’re thanks is enough. Glad to be of help!

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘PHP help’ is closed to new replies.