/ Published in: PHP

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function navigation() { global $wpdb, $post; $query = $wpdb->get_results("SELECT ID, post_title FROM {$wpdb->prefix}posts WHERE post_status = 'publish' AND post_type = 'page' AND post_parent = 0"); echo '<div id="nav">'; echo '<ul>'; foreach ($query as $obj) { echo '<li><a href="'.get_bloginfo('wpurl').'/?page_id='.$obj->ID.'">'.$obj->post_title.'</a></li>'; $sub_query = $wpdb->get_results("SELECT ID, post_title, post_parent FROM {$wpdb->prefix}posts WHERE post_status = 'publish' AND post_type = 'page' AND post_parent = {$obj->ID}"); foreach($sub_query as $sub_obj) { if($post->ID == $sub_obj->post_parent) echo '<li><a href="'.get_bloginfo('wpurl').'/?page_id='.$sub_obj->ID.'" class="subpage">'.$sub_obj->post_title.'</a></li>'; if($post->post_parent == $sub_obj->post_parent) echo '<li><a href="'.get_bloginfo('wpurl').'/?page_id='.$sub_obj->ID.'" class="subpage">'.$sub_obj->post_title.'</a></li>'; } } echo '</ul>'; echo '</div>'; }
Comments
