Problem excluding pages from Wordpress Navbar.

efeezy

New member
Oct 5, 2007
5,250
136
0
50
So most Wordpress themes will use

<?php wp_list_pages();?>

to pull the pages for the navigation bar. I know that if I use

<?php wp_list_pages('exclude=17,38');?> Pages 17 & 18 won't show.

So here's the issue...my theme uses

<?php dp_list_pages();?> And when I try to put the exclusion in there, it
completely jacks my whole theme and nothing works. I've gone into the functions.php
file and here's the associated code with the dp_list_pages

# 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
}
}
}

I can't figure out for my life how to simply exclude two pages I don't want to show in the nav bar. I had a plugin running called exclude pages, but it only works with themes that have the wp_list_pages code. This is starting to piss me off. Anyone have an idea or two? Thanks.
 


the dp_list_pages function does not except any variables. You would have to manually add ... AND $wpdb->posts.post.ID != '17' or $wpdb->posts.post.ID != '138' ... ORDER ...

That or rewrite the function to either exclude the posts from sql query or the foreach loop.
 
Can you just swap out the default code?

If not, I'd say you need to add to that if($pageposts) statement and tell it to disregard pages matching the value of a variable that you later define in ('exclude=17,38')
 
the dp_list_pages function does not except any variables. You would have to manually add ... AND $wpdb->posts.post.ID != '17' or $wpdb->posts.post.ID != '138' ... ORDER ...

That or rewrite the function to either exclude the posts from sql query or the foreach loop.

So in the function code that I listed above, what does that need to look like exactly to make that work? I'm not a coder, so please forgive me if this is a lame question.
 
function dp_list_pages($exclude=NULL) {
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($exclude){
if (!in_array($post->ID, $exclude)) {
?><li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></li><?php
}
}
else{
?><li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></li><?php
}

}
}
}
$dp_list_exclude = array('7','30');
dp_list_pages($dp_list_exclude);
That will still call all pages via sql but remove them from the foreach. Would probably be more viable doing it from the sql query but this will work.
 
Hypex...gave that a try, but what it's doing is adding a centered text list of my navigation pages above the header and moving everything down.
 
Im not sure why, this is what the original script outputs for me
HTML:
<li><a href="http://nswsydnlp18/wordpress/?page_id=2">About</a></li><li><a href="http://nswsydnlp18/wordpress/?page_id=31">test</a></li>
This is what mine outputs (without exclusion)

HTML:
<li><a href="http://nswsydnlp18/wordpress/?page_id=2">About</a></li><li><a href="http://nswsydnlp18/wordpress/?page_id=31">test</a></li>
If i exclude page 2 (about) i get

HTML:
<li><a href="http://nswsydnlp18/wordpress/?page_id=31">test</a></li>

Out put of the functions seem to be generating the same result.