Remove pages from top nav
-
Hello:
I am trying to hide pages from top nav. Here are the problems I’ve encountered so far in trying to hide them:
editing code in header.php to exclude pages hasn’t worked because the theme I am using has “dp_list_pages” instead of the more common “wp-list-pages”.
Many people have tried to hide pages from the top nav. Excluding pages has thus far not worked. I also tried to order pages using plugins such as “Page Mash” and “My Page Order” to no avail. I also tried designating certain pages as “private” so as to hide them from top nav, but then the pages are not viewable even as you type in the URL or give hyperlinks to them.
I also tried “exclude pages” plugin but it didn’t work either.
Anybody with suggestions or troubleshooting is greatly appreciated.
-Allen
crdindustrialsales.com
-
I think you’ll need to track down the dp_list_pages() function in your theme (start with functions.php) and literally see how it creates your page list and how/if you can amend it to allow you to specify excluded pages.
Esmi:
Here’s how it goes. Do you suggest I can fix this bit of PHP?
# Displays a list of pages function dp_list_pages() { global $wpdb; $querystr = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' ORDER BY $wpdb->posts.post_title ASC"; $pageposts = $wpdb->get_results($querystr, OBJECT); if ($pageposts) { foreach ($pageposts as $post) { ?><li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></li><?php } }Try changing it to something like:
# Displays a list of pages function dp_list_pages() { global $wpdb; $querystr = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' ORDER BY $wpdb->posts.post_title ASC"; $pageposts = $wpdb->get_results($querystr, OBJECT); if ($pageposts) { foreach ($pageposts as $post) { if( !is_page( array( 'Foo', 'Wibble', 'About') ) ) ?><li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></li><?php } }substituting the titles of the pages you want to exclude.
It appears that this is the only bit of code changed:
if( !is_page( array( 'Foo', 'Wibble', 'About') ) )And here’s what I found from Snippet 4 in the conditional tags help:
if(is_page()&&($post->post_parent==$pid||is_page($pid))) return true; // we're at the page or at a sub page else return false; // we're elsewhere };When I implemented the code you posted, and substituted “foo” “wibble” “about” with actual pages I have, the whole site went blank. I couldn’t even log into wp-admin, and then I just used FTP software to replace the altered functions.php with the stock funtion.php page.
Any suggestions?My bad – a missing ‘{‘. Try:
# Displays a list of pages
function dp_list_pages() {
global $wpdb;
$querystr = “SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts WHERE $wpdb->posts.post_status = ‘publish’ AND $wpdb->posts.post_type = ‘page’ ORDER BY $wpdb->posts.post_title ASC”;
$pageposts = $wpdb->get_results($querystr, OBJECT);
if ($pageposts) {
foreach ($pageposts as $post) {
if( !is_page( array( ‘Foo’, ‘Wibble’, ‘About’) ) ) {?>Here’s the new code implemented, but check out the Web site to see how it is rendered. Am I supposed to type “exclude” somewhere in there? The Snippet 4 instuctions just don’t make sense to me. THanks much for all your help!
http://www.crdindustrialsales.comDisplays a list of pages function dp_list_pages() { global $wpdb; $querystr = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' ORDER BY $wpdb->posts.post_title ASC"; $pageposts = $wpdb->get_results($querystr, OBJECT); if ($pageposts) { foreach ($pageposts as $post) { if( !is_page( array( 'exclude this page') ) ) ?>"><?php echo $post->post_title; ?></a></li><?php } } }# Displays a list of pages function dp_list_pages() { global $wpdb; $querystr = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' ORDER BY $wpdb->posts.post_title ASC"; $pageposts = $wpdb->get_results($querystr, OBJECT); if ($pageposts) { foreach ($pageposts as $post) { if( !is_page( array( 'Foo', 'Wibble', 'About') ) ) {?> # ID); ?>"><?php echo $post->post_title; ?> <?php } }Substitute Foo, Wibble, and About with the names of the pages you want to exclude.
Actually that code rendered my page blank even though I only tried to exclude one page. Is the following the path to exlcuding?
is_page(array(<em>page</em>'excludepage'))What’s the title of the page you want to exclude?
There are about 15 pages on the site. I will excluding most except for four or five pages. For example, I’d like to exclude automation control. The page title is ‘automation control’ and the friendly URL is http://www.crdindustrialsales.com/automation-control
There are about 15 pages on the site. I will excluding most except for four or five pages. For example, I’d like to exclude automation control. The page title is ‘automation control’ and the friendly URL for that page is:
http://www.crdindustrialsales.com/automation-control
When you gave me a variation of your first post, it rendered it blank, but the following code rendered what you now see live at http://www.crdindustrialsales.com
# Displays a list of pages function dp_list_pages() { global $wpdb; $querystr = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' ORDER BY $wpdb->posts.post_title ASC"; $pageposts = $wpdb->get_results($querystr, OBJECT); if ($pageposts) { foreach ($pageposts as $post) { if( !is_page( array( 'automation-contol') ) ) ?>"><?php echo $post->post_title; ?></a></li><?php } }If you only want 5 out of 15 pages, you’re better of using an include rather than an exclude.
# Displays a list of pages function dp_list_pages() { global $wpdb; $querystr = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' ORDER BY $wpdb->posts.post_title ASC"; $pageposts = $wpdb->get_results($querystr, OBJECT); if ($pageposts) { foreach ($pageposts as $post) { if( is_page( array( 'Page 1', 'Page 2', 'Page 3', 'Page 4', 'Page 5' ) ) ) ?><li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></li><?php } }All pages still show up in top nav, even with that code you provided. I listed only one page and it still displays all pages in top nav. Any idea why?
Esmi, you have been diligent in patient in your help. Thanks much for the work you’ve put into it!
Esmi:
Thanks for all the help. I finally went with another theme in order to use pagemash plugin.
The topic ‘Remove pages from top nav’ is closed to new replies.