I need a little help editing a WP Theme. I'm using studiopress from dailyblogtips (not studiopress.com). My main issue is that I would like to remove my child/subpages from the top navigation. Here is the current header code: <div id="nav"> <?php function get_the_pa_ges() { global $wpdb; if ( ! $these_pages = wp_cache_get('these_pages', 'pages') ) { $these_pages = $wpdb->get_results('select ID, post_title from '. $wpdb->posts .' where post_status = "publish" and post_type = "page" order by ID'); } return $these_pages; } function list_all_pages(){ $all_pages = get_the_pa_ges (); foreach ($all_pages as $thats_all){ $the_page_id = $thats_all->ID; if (is_page($the_page_id)) { $addclass = ' class="current_page"'; } else { $addclass = ''; } $output .= '<li' . $addclass . '><a href="'.get_permalink($thats_all->ID).'" title="'.$thats_all->post_title.'"><span>'.$thats_all->post_title.'</span></a></li>'; } return $output; } ?> <ul> <?php if (is_home()) { $addclass = ' class="current_page"'; } else { $addclass = ''; } echo list_all_pages();?> </ul> <div class="cleared"></div> PHP: What do I need to add/remove/replace to remove child pages from the top navigation? Just FYI, I altered the original code to remove the 'home' link (just 1 line I think). I'm not a php coder, so specific code and instructions would be greatly appreciated! Also, the page ordering doesn't seem to work. If I add a page, it goes to the end (right side) even using the page IDs. If I delete the preceding page and recreate it, it will go to the end. Any advice? Thanks in advance.
You could try a wp plugin called page lists plus. It offers a check box on each page to list in nav or not. It also lets you change the menu name of the page/post.
No problem... As for your ordering issue, you say you are using page ids? How so? The best way to order pages is to use the page order field under the page attributes heading. Use 100 for the page you want on the right, and 1 for the page you want on the left...then use other numbers in between to order your other pages...
$these_pages = $wpdb->get_results('select ID, post_title from '. $wpdb->posts .' where post_status = "publish" and post_type = "page" and post_parent = 0 order by ID'); Code (markup): I added a requirement that the pages have no parent so it should exclude all child pages. I have not tried it yet but it should work.
This code seems to work. I added it and child pages are not showing. Thanks! I'm still having problems with the page ordering...I can change a page id and it simply won't move. Any ideas? Rep added for both of you that offered up suggestins. Thanks again.
I've got 4 pages right now - 3 parent and one child. I've got the code replaced as suggested by Cash Nebula. The parent page id's are 1, 2, and 50. #50 shows up before #2. Child page was 2, but now it's 75 and still no change (but my child pages are not showing due to code change - the way I wanted it). Dunno what's going on with the page ordering.
Where it says "order by ID", try changing that to one of these: order by menu_order order by post_title order by post_name order by post_date I think you need to set order numbers for the pages before menu_order will work, like is says on the Codex:
Hot damn! That works! I used order by menu order and it worked. Thanks again, really appreciate the help!