• Resolved oldbag66

    (@oldbag66)


    Hi, i want to add a message so if a catagory doesnt have any posts a message is display saying so, “sorry no posts”.

    Im am using a list of conditional staments for a sidebar and would like to use it here:

    <ul class="rightcol">
    <?php global $post; $myposts = get_posts('numberposts=10&amp;category=18'); foreach($myposts as $post) :?>
    <li><span class="threecolsmall"><?php the_time('j M y') ?></span><br />
    <a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>

    not sure how to add this into the PHP.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi
    try this code

    <ul class="rightcol">
    <?php
    $myposts = new WP_Query();
    $myposts->query('showposts=10&amp;cat=18');
    
    if ($myposts->post_count == 0) { ?>
       <li>sorry no posts</li>
    <?php } else {
      while ($myposts->have_posts()) : $myposts->the_post(); ?>
        <li><span class="threecolsmall"><?php the_time('j M y') ?></span><br />
        <a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
      <?php endwhile;
    } ?>
    </ul>
    Thread Starter oldbag66

    (@oldbag66)

    perfect, thankyou.

    Zeal

    (@zealwebdrumbeatcom)

    HEELP!

    Hi, i want to add a message so if a ‘parent page’ link doesnt have any ‘subpages’ a message is display saying so, “sorry no subpages”.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘conditional statements when category has no posts display message’ is closed to new replies.