WP Pro - Web Design, Development & Pro WordPress Hosting for Serious Bloggers


Anatomy of a Magazine Style Premium WordPress Theme – Part 3.2 “Conditional Navigation Menus”


Welcome back! Have you subscribed to my RSS feed? If not, please consider doing so. Thanks for again for visiting!

When you dice the theme, we will find that aside from the usual page tag which looks like this:

  1. <?php wp_list_pages(’sort_column=menu_order&depth=1&title_li=’); ?>

You will notice we have added the conditional tag to call child pages within the same “div”, which looks like this:

	<?php global $notfound; ?>
	<?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'")) { ?> <li>Subpage:</li> <?php wp_list_pages('sort_column=menu_order&title_li=&child_of='. $parent_id); ?>
	<?php } } ?>

If you look closely at what the conditional code is required to do, you will find that it is designed to display sub-pages when parent pages with sub-pages are visited. No sub-pages are displayed whe you are on pages without sub-pages or on other post or category page templates.

All you need to do is add the above code within the same “div” as the main navigation menu (either in the header or sidebar) and that is pretty much it. So there you have it, the simple conditional navigation menu. Next time, we will dig into dropdown menus using CSS and JavaScript.

3 Responses to “Anatomy of a Magazine Style Premium WordPress Theme – Part 3.2 “Conditional Navigation Menus””

  1. Much appreciated! Thanks guys!

  2. Thanks very for this useful tutorial. It is inspiring me to create my own wp theme


Trackbacks

  1. When To Use Magazine-Style Themes For Blogs? | aboutCREATION

Leave a Response

Some Useful Info

Use SimpleCode while including codes.

The links from all comments have the no-follow tag to prevent spammers from gaming their way up into SERP. So please keep the comments clean, try not to use keywords as "Names" or post unnecessary links in the comments. Thank you for cooperating.



Copyright © WP Pro - CSS | XHTML | Login | Return to Top ↑