PHP help
-
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
-OrangesBut 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)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘PHP help’ is closed to new replies.