I am using the code below on my sidebar. The sidebar changes depending on the page parent I have selected. The sidebar will show the parent and all its children. So if the parent is Fruit, the sidebat would show
Fruit Subpages
-Apples
-Oranges
But if the parent doesnt have any children, it shows a blank box.
How can I alter the code so it shows the parents name even if it has no children?
Code:
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'")) { ?>