List posts, if more than one.
-
I have this code that displays all the posts as a list in the same category as the post you are on.
<h2 class="bluebottom"><?php $categories = get_the_category(); foreach($categories as $category) { echo $category->name . ' '; } ?></h2> <ul> <?php global $post; $category = get_the_category($post->ID); $category = $category[0]->cat_ID; $myposts = get_posts(array('numberposts' => 99, 'category__in' => array($category), 'post__not_in' => array($post->ID),'post_status'=>'publish')); foreach($myposts as $post) : setup_postdata($post); ?> <li> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> </li> <?php endforeach; ?> <?php wp_reset_query(); ?> </ul>
How would I modify this code so the <h2></h2> at the top only appears if there is more than one post in the category?
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘List posts, if more than one.’ is closed to new replies.