• 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)
  • 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

    Hope that helps?
    Derek M.

    Thread Starter fewster101

    (@fewster101)

    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?

    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.