Title: php code help &#8211; category posts
Last modified: August 19, 2016

---

# php code help – category posts

 *  [fewster101](https://wordpress.org/support/users/fewster101/)
 * (@fewster101)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/php-code-help-category-posts/)
 * Hi there.
    I’m in the process of building a site requiring current job postings(
   which are managed through categories). But there’s a section I can’t figure out.
   The spot where I have Nothing available at this time, I would like for it to 
   appear automatically if there are no posts in the category.
 * what I have so far is this, but I don’t want to have to keep changing it manually
   to add in the nothing available at this time part. Hopefully I’m explaining this
   right.
 * This is part of a page template that i’ve created to list these.
 *     ```
       <h3>Current Employment Opportunities</h3>
       <h4>Department 1<ul>
       <h5>Nothing available at this time</h5></ul>
       <ul>
       <?php$latest = get_posts('cat=-1,-2,-3,-7,-8,-10,-11&numberposts=10');
       foreach( $latest as $post ):?>
       <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | <?php the_time('j M'); ?></li>
       <?php endforeach ?>
       </ul></h4>
       <h4>Department 2<ul>
       <?php$latest = get_posts('cat=-1,-2,-3,-4,-5,-6,-8,-9,-10,-11&numberposts=10');
       foreach( $latest as $post ):?>
       <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | <?php the_time('j M'); ?></li>
       <?php endforeach ?>
       </ul></h4>
       ```
   

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

 *  [nex2nun](https://wordpress.org/support/users/nex2nun/)
 * (@nex2nun)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/php-code-help-category-posts/#post-920709)
 * Take a look at the end of your loop, what if you try this.
 *     ```
       <?php endforeach; else: ?>
       <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
       <?php endif; ?>
       ```
   
 * If there are not posts found, returns message:
 * >  Sorry, no posts matched your criteria.
 * [WordPress Codex: The_Loop](http://codex.wordpress.org/The_Loop)
 * Hope that helps?
    Derek M.
 *  Thread Starter [fewster101](https://wordpress.org/support/users/fewster101/)
 * (@fewster101)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/php-code-help-category-posts/#post-920932)
 * I tried that. Didn’t work. Just kept giving me an error. I tried a few variations,
   didn’t seem to work either.
    Any other suggestions?
 *  [nex2nun](https://wordpress.org/support/users/nex2nun/)
 * (@nex2nun)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/php-code-help-category-posts/#post-920942)
 * What error were you getting?

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

The topic ‘php code help – category posts’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [nex2nun](https://wordpress.org/support/users/nex2nun/)
 * Last activity: [17 years, 6 months ago](https://wordpress.org/support/topic/php-code-help-category-posts/#post-920942)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
