oldbag66
Member
Posted 2 years ago #
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&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.
Hi
try this code
<ul class="rightcol">
<?php
$myposts = new WP_Query();
$myposts->query('showposts=10&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>
oldbag66
Member
Posted 2 years ago #
Zeal Murapa
Member
Posted 2 years ago #
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".