Title: PHP help
Last modified: August 18, 2016

---

# PHP help

 *  [zonetrap](https://wordpress.org/support/users/zonetrap/)
 * (@zonetrap)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/)
 * 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](https://wordpress.org/support/users/zonetrap/)
 * (@zonetrap)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-543963)
 * No one?
 *  [metialb](https://wordpress.org/support/users/metialb/)
 * (@metialb)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-543964)
 * do you have a link of your blog?
 *  Thread Starter [zonetrap](https://wordpress.org/support/users/zonetrap/)
 * (@zonetrap)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-543967)
 * [http://www.pokersyndicate.com](http://www.pokersyndicate.com)
 *  Thread Starter [zonetrap](https://wordpress.org/support/users/zonetrap/)
 * (@zonetrap)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-543993)
 * Any luck with this?
 *  Thread Starter [zonetrap](https://wordpress.org/support/users/zonetrap/)
 * (@zonetrap)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-544000)
 * bumping it.
 *  Thread Starter [zonetrap](https://wordpress.org/support/users/zonetrap/)
 * (@zonetrap)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-544022)
 * 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](https://wordpress.org/support/users/peiqinglong/)
 * (@peiqinglong)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-544025)
 * In this last line:
 * `<?php } } ?>` change it to reflect `<?php } else {} } ?>` and see if that works.
 *  [peiqinglong](https://wordpress.org/support/users/peiqinglong/)
 * (@peiqinglong)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-544026)
 * 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](https://wordpress.org/support/users/zonetrap/)
 * (@zonetrap)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-544028)
 * 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](https://wordpress.org/support/users/peiqinglong/)
 * (@peiqinglong)
 * [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-544036)
 * 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.

 * In: [Installing WordPress](https://wordpress.org/support/forum/installation/)
 * 10 replies
 * 3 participants
 * Last reply from: [peiqinglong](https://wordpress.org/support/users/peiqinglong/)
 * Last activity: [19 years ago](https://wordpress.org/support/topic/php-help-1-4/#post-544036)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
