zonetrap
04-03-2007, 07:39 PM
I am working in Wordpress, and I am a php newbie. 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 not show the "empty box" when the page has no children? I think it needs some sort of loop, but as I said before I'm a newbie, still learning all this. Thanks for the help here. I really want to learn more about PHP, and I feel this is a good example. For reference, I am using it on http://www.pokersyndicate.com
<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 } } ?>
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 not show the "empty box" when the page has no children? I think it needs some sort of loop, but as I said before I'm a newbie, still learning all this. Thanks for the help here. I really want to learn more about PHP, and I feel this is a good example. For reference, I am using it on http://www.pokersyndicate.com
<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 } } ?>