Title: Display Specific Post based on category
Last modified: August 19, 2016

---

# Display Specific Post based on category

 *  Resolved [acmc](https://wordpress.org/support/users/acmc/)
 * (@acmc)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/display-specific-post-based-on-category/)
 * I am trying to create a template page to serve as category pages with an else
   if to display specific post based on category. New to php, so i think my syntax
   is incorrect. This is what i have pieced together:
    <?php get_header(); ?> <div
   id=”content” class=”narrowcolumn”>
 * <?php if (is_category(‘3’) ):
    ?>
 *  <?php query_posts(‘p=17’); ?>
    <?php while (have_posts()) : the_post(); ?> <
   h4><?php the_title(); ?></h4> <?php the_content(); ?>
 *  <?php } elseif (is_category(’13’) ):
 *  <?php query_posts(‘p=11’); ?>
    <?php while (have_posts()) : the_post(); ?> <
   h4><?php the_title(); ?></h4> <?php the_content(); ?>
 *  <?php else : ?>
    //whatever goes in here <?php endif; ?>
 * Displays blank page. Unsure what I am doing wrong. I will continue searching,
   but it seems the search function on the wp site is not working right now making
   it exceedingly difficult:-/ any help GREATLY appreciated

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

 *  [Vaughan](https://wordpress.org/support/users/vaughan-van-dyk/)
 * (@vaughan-van-dyk)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/display-specific-post-based-on-category/#post-789272)
 * Hi,
 * Most of your code here was correct and you got the use of is_category and query_posts
   perfectly (those usually trip up many of us 🙂 The only issues were where and
   how you were closing your if structures and while loops. For example, in line
   12 see how you have a closing bracket but no opening bracket earlier?
 * It’s also a little complex because you’re using the ‘shorthand’ style of notating
   decision structures (by using the : instead of brackets). There’s nothing wrong
   with that, but I just find it less clear than brackets. If you are going to do
   that though, remember to use endif; and endwhile; where appropriate.
 * I’ve fixed this as follows and for demonstration purposes combined shorthand 
   for the while loops and brackets for the if structures:
 *     ```
       <?php get_header(); ?>
       <div id="content" class="narrowcolumn">
   
       <?php if (is_category('3') ) { ?>
        <?php query_posts('p=17'); ?>
        <?php while (have_posts()) : the_post(); ?>
          <h4><?php the_title(); ?></h4>
          <?php the_content(); ?>
        <?php endwhile;
       } elseif (is_category('13') ) { ?>
        <?php query_posts('p=11'); ?>
        <?php while (have_posts()) : the_post(); ?>
          <h4><?php the_title(); ?></h4>
          <?php the_content(); ?>
        <?php endwhile;
       } else { ?>
        //whatever goes in here
       <?php } ?>
       ```
   
 * Hope that helps.
    Vaughan
 *  Thread Starter [acmc](https://wordpress.org/support/users/acmc/)
 * (@acmc)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/display-specific-post-based-on-category/#post-789392)
 * Vaughan
 * You are a life-saver! thank you. will continue to play and see if i can get this
   thing to behave;-)
 * **Ann

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

The topic ‘Display Specific Post based on category’ is closed to new replies.

## Tags

 * [syntax error](https://wordpress.org/support/topic-tag/syntax-error/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [acmc](https://wordpress.org/support/users/acmc/)
 * Last activity: [17 years, 10 months ago](https://wordpress.org/support/topic/display-specific-post-based-on-category/#post-789392)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
