0

I am creating a custom theme for wordpress, which will have a settings page. i am adding the option to exclude pages from the navigation, which will simply work on the page id separated by a ","

here is the code i have so far:

    <ul class="tabs">
<?php
    $exmenuitems = get_option('exmenuitems');
    $recentPosts = new WP_Query();
    $recentPosts->query (array (
    'post__not_in' => array($exmenuitems),
    'post_type' => 'page',
    'showposts' => $menuitems
));
 while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<?php $slug = basename(get_permalink());?>   
<li><a href="#<?php echo $slug; ?>"><?php the_title();?></a></li>
<?php endwhile; ?>
</ul>

this works fine excluding just 1 page id. but when i try and exclude more than 1 id it doesn't work, only the first id in the text input will get excluded and the other remain visible.

any help would be greatly appreciated.

Dan

4
  • Does your $exmenuitems contains an array of page Ids? – The Alpha Apr 9 '12 at 21:44
  • yes it currently has 3 id's – danyo Apr 9 '12 at 21:48
  • 1
    May be you should use 'post__not_in' => $exmenuitems because it's already an array. – The Alpha Apr 9 '12 at 21:51
  • showposts should contain an int value and it's deprecated, instead you should use posts_per_page, codex.wordpress.org/Class_Reference/… – The Alpha Apr 9 '12 at 21:53
2

You probably want to explode your list of page ID's using the explode function.

Something like;

<?php
    $exmenuitems = explode(",",get_option('exmenuitems'));
    $recentPosts = new WP_Query();
    $recentPosts->query (array (
    'post__not_in' => $exmenuitems,
    'post_type' => 'page',
    'showposts' => $menuitems
));

I'd recommend using the WordPress Menu building functions and admin interface. Its much more intuitive for end users to build their navigation menus via drag n drop that using page ID's.

4
  • i have tried the explode fnuction and doesn't seem to work. when i echo it out i just get "array" – danyo Apr 9 '12 at 21:53
  • cheers guys solved! – danyo Apr 9 '12 at 21:54
  • How did you solve it, would you mind to share ? – The Alpha Apr 9 '12 at 21:55
  • i did what you said and removed the array from the 'post__not_in' and also used the explode function as Dale stated. – danyo Apr 9 '12 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.