Cannot exclude page from menu

5 replies
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
#exclude #menu #page
  • Profile picture of the author SmartWeb
    Originally Posted by HenrikPoulsen View Post

    Hey all



    The code for the nav bar is as follows

    <div id="nav">
    <?php function get_the_pa_ges() {
    global ;
    if ( ! = wp_cache_get('these_pages', 'pages') ) {
    = ('select ID, post_title from '. .' where post_status = "publish" and post_type = "page" order by ID');

    }
    return ;
    }

    function list_all_pages(){

    = get_the_pa_ges ();
    foreach ( as ){
    = ;

    if (is_page()) {
    = ' class="current_page"';
    } else {
    = '';
    }
    .= '<li' . . '><a href="'.get_permalink().'" title="'..'"><span>'..'</span></a></li>';
    }

    return ;
    }
    ?>
    <ul>
    <?php

    if (is_home()) {
    = ' class="current_page"';
    } else {
    = '';
    }

    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
    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.
    {{ DiscussionBoard.errors[2669376].message }}
  • Profile picture of the author HenrikPoulsen
    Thank you very much this did the trick nicely
    {{ DiscussionBoard.errors[2669916].message }}
    • Profile picture of the author Big Squid
      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.
      {{ DiscussionBoard.errors[2670138].message }}
      • Profile picture of the author HenrikPoulsen
        Originally Posted by Big Squid View Post

        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.
        Thanks I'll try that.

        One thing I like about hard-coding the thing myself though is that I learn how the whole thing works
        {{ DiscussionBoard.errors[2670163].message }}
    • Profile picture of the author SmartWeb
      Originally Posted by HenrikPoulsen View Post

      Thank you very much this did the trick nicely
      Glad that you got the solution you wanted.
      {{ DiscussionBoard.errors[2670867].message }}

Trending Topics