Excluding pages from navigation menu
-
Hi
I need to exclude 3 legal pages from my top navigation menu.
The WP documentation and other forum topics describe amending the <?php wp_list_pages?> line in the theme’s header.php (Panorama theme). But I don’t have this line, instead I have this, so I’m not sure what to do.
Thanks
<?php if (get_option(‘ap_includeHome’) == 0){ ?>
<li class=”<?php if (((is_home()) && !(is_paged())) or (is_archive()) or (is_single()) or (is_paged()) or (is_search())) { ?>current_page_item<?php } else { ?>page_item<?php } ?>”>/”><?php _e(‘Home’) ; ?>
<?php } ?>
<?php ap_buildMenu(); ?>
-
ap_buildMenu is a function in that theme’s functions.php so looks like you would change
wp_list_pages('title_li=&sort_column='.$mo. '&depth=0'. $excString);
to something like this to exclude page ids 7, 14, and 27
wp_list_pages('exclude=7,14,27title_li=&sort_column='.$mo. '&depth=0'. $excString);
Note that the Home link is hardcoded in header.php
Related:
Stepping Into Template Tags
Stepping Into Templates
Template HierarchyThanks MichaelH for pointing out where the function is.There are actually two different buildMenu functions in this page.
Unfortunately the pages aren’t being excluded when I do as you’ve suggested above.
<?php
load_theme_textdomain(‘panorama’);// Widgets
if(function_exists(‘register_sidebar’)) {register_sidebar(array(
‘name’ => __(‘Sidebar’),‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ”,
‘before_title’ => ‘<h3>’,
‘after_title’ => ‘</h3>’,));
}
add_filter(‘comments_template’, ‘legacy_comments’);
function legacy_comments($file) {
if ( !function_exists(‘wp_list_comments’) )
$file = TEMPLATEPATH . ‘/legacy.comments.php’;
return $file;
}define(AP_LAYOUT, ‘r’);
define(AP_LINKCOLOUR, ‘#454673’);
define(AP_HOVERCOLOUR, ‘#4B5BAD’);
define(AP_HEADERIMAGE, ‘a_rome_street.jpg’);function buildMenu(){
$mo = ap_getPageMenuOrder();
$exc = get_option(‘ap_pagesOmit’);$excString = (!empty($exc)) ? ‘&exclude=’ . $exc : ”;
wp_list_pages(‘exclude=424,429,432title_li=&sort_column=’.$mo. ‘&depth=-1’. $excString);
return NULL;
}function ap_add_theme_page() {
global $wpdb;$errorFlag = false;
if ($_GET[‘page’] == basename(__FILE__)) {// save settings
if ( ‘save’ == $_REQUEST[‘action’] ) {if (valid_colour($_REQUEST[‘ap_linkColour’])){
update_option(‘ap_linkColour’, $_REQUEST[‘ap_linkColour’]);
} else {
$errorFlag = true;
}if (valid_colour($_REQUEST[‘ap_hoverColour’])){
update_option(‘ap_hoverColour’, $_REQUEST[‘ap_hoverColour’]);
} else {
$errorFlag = true;
}if (($_REQUEST[‘ap_pageMenuOrder’] == ‘menu’) ||
($_REQUEST[‘ap_pageMenuOrder’] == ‘alpha’) ||
($_REQUEST[‘ap_pageMenuOrder’] == ‘pageid’)
){
update_option(‘ap_pageMenuOrder’, $_REQUEST[‘ap_pageMenuOrder’]);
} else {
$errorFlag = true;
}if (checkPagesOmit($_REQUEST[‘ap_pagesOmit’])){
update_option(‘ap_pagesOmit’, trim($_REQUEST[‘ap_pagesOmit’]));
} else {
$errorFlag = true;
}$ap_includeHome = (isset($_REQUEST[‘ap_includeHome’])) ? ‘0’: ‘1’;
update_option(‘ap_includeHome’, $ap_includeHome);
$ap_headerRotate = (isset($_REQUEST[‘ap_headerRotate’])) ? ‘0’: ‘1’;
update_option(‘ap_headerRotate’, $ap_headerRotate);
$ap_dateTimeFormat = (isset($_REQUEST[‘ap_dateTimeFormat’])) ? ‘0’: ‘1’;
update_option(‘ap_dateTimeFormat’, $ap_dateTimeFormat);
update_option(‘ap_rssUrl’, attribute_escape(trim($_REQUEST[‘ap_rssUrl’])));
update_option(‘ap_twitterName’, attribute_escape(trim($_REQUEST[‘ap_twitterName’])));
update_option(‘ap_headerImage’, attribute_escape(trim($_REQUEST[‘ap_headerImage’])));$ap_layout = ($_REQUEST[‘ap_layout’] == ‘l’) ? ‘l’:’r’;
update_option(‘ap_layout’, $ap_layout);// goto theme edit page
if($errorFlag){
header(“Location: themes.php?page=functions.php&error=true”);
die;
} else {
header(“Location: themes.php?page=functions.php&saved=true”);
die;
}// reset defaults
} else if(‘reset’ == $_REQUEST[‘action’]) {
delete_option(‘ap_linkColour’);
delete_option(‘ap_hoverColour’);
delete_option(‘ap_pageMenuOrder’);
delete_option(‘ap_pagesOmit’);
delete_option(‘ap_rssUrl’);
delete_option(‘ap_twitterName’);
delete_option(‘ap_headerImage’);
delete_option(‘ap_headerRotate’);
delete_option(‘ap_dateTimeFormat’);
delete_option(‘ap_layout’);
delete_option(‘ap_includeHome’);header(“Location: themes.php?page=functions.php&reset=true”);
die;}
}add_theme_page(__(‘Panorama Theme Options’,’panorama’), __(‘Panorama Theme Options’,’panorama’), ‘edit_themes’, basename(__FILE__), ‘ap_theme_page’);
}
include(TEMPLATEPATH . ‘/library/theme_options.php’);
include(TEMPLATEPATH . ‘/library/formFunctions.php’);add_action(‘admin_menu’, ‘ap_add_theme_page’);
function valid_colour($var){
$regex = ‘^#([a-f]|[A-F]|[0-9]){6}^’;
return preg_match($regex,$var);
}function ap_linkColour() {
$tc = get_option(‘ap_linkColour’);
return (empty($tc)) ? AP_LINKCOLOUR : $tc;
}function ap_hoverColour() {
$hc = get_option(‘ap_hoverColour’);
return (empty($hc)) ? AP_HOVERCOLOUR: $hc;
}function ap_getPageMenuOrder() {
switch (get_option(‘ap_pageMenuOrder’)){
case (‘alpha’):
$mo = ‘post_title’;
break;case (‘pageid’):
$mo = ‘ID’;
break;default:
$mo = ‘menu_order’;
}return $mo;
}function checkPagesOmit($str){
if (empty($str)) return true;
$regex = ‘/^[0-9 ,]+$/’;
return preg_match($regex,$str);
}function ap_rssLink(){
$link = get_option(‘ap_rssUrl’);
return (!empty($link)) ? $link : get_bloginfo(‘rss2_url’);
}function ap_twitterLink(){
$name = get_option(‘ap_twitterName’);
return (!empty($name)) ? sprintf(‘<img style=”vertical-align:-3px;” alt=”Twitter” src=”%s/images/twitter.gif” height=”16″ width=”16″ /> %s %s Twitter | ‘, get_bloginfo(‘template_directory’), $name, $name, get_bloginfo(‘name’), __(‘on’,’panorama’)) : ”;
}
function findImageFile(){
$dir = TEMPLATEPATH . ‘/header_images’;
if(function_exists(‘scandir’)) {
$ap_files = deDotifyFiles(scandir($dir));
} else {$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$ap_files[] = $filename;
}
$ap_files = deDotifyFiles($ap_files);
sort($ap_files);
}
return $ap_files;
}function deDotifyFiles($files){
while(($n = array_search(‘.’,$files)) > -1)
unset($files[$n]);
while(($n = array_search(‘..’,$files)) > -1)
unset($files[$n]);
return $files;
}function ap_headerImage(){
$imageFile = (get_option(‘ap_headerRotate’) == 0) ?
ap_headerImageDynamic():
ap_headerImageStatic();if (!empty($imageFile) && file_exists(TEMPLATEPATH.’/header_images/’.$imageFile)) {
return sprintf(‘background: url(“%s/header_images/%s”) top center no-repeat;’,get_bloginfo(‘template_directory’), $imageFile);} else {
return ‘background: green;’;
}}
function ap_headerImageStatic(){
$imageFile = get_option(‘ap_headerImage’);
if (empty($imageFile)){
foreach (findImageFile() as $img) {if ($img != ‘.’ && $img != ‘..’ && file_exists(TEMPLATEPATH.’/header_images/’.$img)){
$imageFile = $img;
break;
}
}
}
return $imageFile;
}function ap_headerImageDynamic(){
$imgs = findImageFile();
if(!is_array($imgs)) return ”;
shuffle($imgs);
return $imgs[0];
}function ap_buildMenu(){
$mo = ap_getPageMenuOrder();
$exc = get_option(‘ap_pagesOmit’);$excString = (!empty($exc)) ? ‘&exclude=’ . $exc : ”;
wp_list_pages(‘title_li=&sort_column=’.$mo. ‘&depth=0’. $excString);
return NULL;
}function ap_layout(){
$layout = get_option(‘ap_layout’);
echo (!empty($layout)) ? $layout : ‘r’;
return NULL;
}$ap_dateFormat = get_option(‘date_format’);
$ap_timeFormat = (get_option(‘ap_dateTimeFormat’) == 0) ? ‘ ‘ . get_option(‘time_format’) : ”;$ap_dateTimeFormat = $ap_dateFormat . $ap_timeFormat;
?>Actually, in Admin->Appearance->Panaroma Theme Options, there is a place to exclude pages from the menu. Just enter the page Id’s separated by commas.
- The topic ‘Excluding pages from navigation menu’ is closed to new replies.