Title: Trouble with a conditional statement
Last modified: August 19, 2016

---

# Trouble with a conditional statement

 *  Resolved [shaun1981](https://wordpress.org/support/users/shaun1981/)
 * (@shaun1981)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/trouble-with-a-conditional-statement/)
 * I am using the following to get a selection of posts from a certain category:
 *     ```
       <ul>
       <?php $recent = new WP_Query("cat=91&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>
       <li><a href="<?php the_permalink() ?>" rel="bookmark">
       <?php the_title(); ?>
       </a></li>
       <?php endwhile; ?>
       </ul>
       ```
   
 * However what I want to do is wrap the whole thing in an IF statement so that 
   it only shows up on a certain page. I have tried multiple ways but keep coming
   back with PHP errors.
 * Is there an easy way to wrap the code above in an IF statement that basically
   says if it is page 2 output this? I’m sure there is but it’s driving me mad at
   the minute!
 * Thanks for the help.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/trouble-with-a-conditional-statement/#post-1425862)
 * you could try this:
 *     ```
       <?php if(is_page('2')) : ?>
       <ul>
       <?php $recent = new WP_Query("cat=91&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>
       <li><a href="<?php the_permalink() ?>" rel="bookmark">
       <?php the_title(); ?>
       </a></li>
       <?php endwhile; ?>
       </ul>
       <?php endif; ?>
       ```
   
 * [http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page](http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page)
 *  Thread Starter [shaun1981](https://wordpress.org/support/users/shaun1981/)
 * (@shaun1981)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/trouble-with-a-conditional-statement/#post-1425865)
 * Excellent thanks. It was the end of the first line I was getting wrong.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Trouble with a conditional statement’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [shaun1981](https://wordpress.org/support/users/shaun1981/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/trouble-with-a-conditional-statement/#post-1425865)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
