Cannot exclude page from menu

by 5 replies
6
Hey all

I'm currently working on my new website using a theme for wordpress

I have hit a small snag and need a little help. I wish to exclude one page from the menu bar at the top but cannot figure out the code

(I have tried the exclude pages from navigation plugin made By Simon Wheatley to no avail)

The code for the nav bar is as follows

<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>
</div> <!-- Closes Nav -->



How would you go about excluding a single page from the nav-bar?

Thanks
#programming #exclude #menu #page
  • Each page has one ID. you can find this via admin login, let me know if you have any issue in finding the ID.
    say you have the ID as '69' . (just an example)
    you can modify the above code, function list_all_pages() as below,

    ------------------

    function list_all_pages(){

    $all_pages = get_the_pa_ges ();
    foreach ($all_pages as $thats_all){
    $the_page_id = $thats_all->ID;

    if($the_page_id != 69)
    {

    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;
    }
    --------------------
    try this. i just added the page ID in the for loop and processed the loop only if the ID is different from the page ID you want to exclude.
  • Thank you very much this did the trick nicely
    • [2] replies
    • If you don't want to hard code it, you can use the WP-HIDE-POST plugin. It works great for that type of stuff.
      • [1] reply
    • Glad that you got the solution you wanted.

Next Topics on Trending Feed