Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following code and need it to exclude the child pages of a page ID;

<?php
      $args = array(
                    'post_type' => 'page',
                    'post_status' => 'publish',
                    'numberposts' => -1,
                    'exclude' => '3984,1939,6006,28,2784',
                    'depth' => 1
                );
                     $postslist = get_posts($args);
                     foreach ($postslist as $post) :
                        setup_postdata($post);
                     ?>
                <li>
                    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                        <?php if ( has_post_thumbnail() ) { the_post_thumbnail('portrait');} else { echo '<img src="#" alt="Something Went Wrong?" title="Sorry - Something went wrong?" />';}?>    
                    </a>
                        <span><?php meta('issue-number'); ?></span>
                </li>

     <?php endforeach; ?>

The 'Depth' does not seem to have any effect...

Thanks!

share|improve this question
    
I think the exclude needs to be an array. so something like: 'exclude' => array(3984,1939,6006,28,2784), might work. Would need to check this though. –  Cristian Aug 25 '11 at 12:37
    
Thanks, but i am not sure you have understood - if you look at the code, i am already excluding individual pages, but i want all child pages of ID= x to be excluded automatically. –  Infocentre Aug 25 '11 at 12:44
    
Oh sorry. I thought the exclude IDs were the child pages. Use the get_pages function instead. It has the appropriate exclude_tree param that will solve your problem –  Cristian Aug 25 '11 at 12:51
    
That's great, thanks Phoenix! –  Infocentre Aug 25 '11 at 13:04

2 Answers 2

There is not depth parameter for get_posts. See http://codex.wordpress.org/Template_Tags/get_posts

You will need to check to see whether the page has a parent and display it if it does not have a parent.

Once you are in the foreach loop add an if statement

<?php if( !$post->parent ): ?>
    <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail('portrait');} else { echo '<img src="#" alt="Something Went Wrong?" title="Sorry - Something went wrong?" />';}?></a>
     <span><?php meta('issue-number'); ?></span>
     </li>
<?php endif: ?>
share|improve this answer
                <?php
      $args = array(
                    'post_type' => 'page',
                    'post_status' => 'publish',
                    'numberposts' => -1,
                    'exclude' => '3984,1939,6006,28,2784',
                    'exclude_tree' => '1939',
                    'sort_order' => 'desc'
                );
                     $postslist = get_pages($args);
                     foreach ($postslist as $post) :
                        setup_postdata($post);

                     ?>
                <li>
                    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                        <?php if ( has_post_thumbnail() ) { the_post_thumbnail('portrait');} else { echo '<img src="#" alt="Something Went Wrong?" title="Sorry - Something went wrong?" />';}?>    
                    </a>
                        <span><?php meta('issue-number'); ?></span>
                </li>

     <?php endforeach; ?>

Thanks to Phoenix - all i needed to do was have get_pages instead. This opened up the extra options i needed

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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