Conditionals help: is_home and is_category
-
Hi everyone. I’m learning more and more PHP everyday, and every time I figure something out, something else doesn’t work! Yay!
Anyway, I am trying to display a welcome message on the front page (in my sidebar) and when on category pages, it is replaced by a listing of recent posts in that category. I got the category part working fine, but can’t figure out how to get rid of the Welcome text on category pages.
Here’s my code:
<?php if ( is_home() ); ?> <h2>Welcome</h2> <?php if ( is_category() ) { ?><h2>Recent Posts</h2> <?php foreach( ( get_the_category() ) as $category ) { $the_query = new WP_Query('category_name=' . $category->category_nicename . '&showposts=5'); while ($the_query->have_posts()) : $the_query->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li> <?php endwhile; ?> <?php } ?> <?php } else { ?><?php } ?>
I’ve tried different ways of ending the first if tag (after the H2 tags), but none work.
Also, will the Welcome text stay on single post pages?
THANKS A LOT!
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Conditionals help: is_home and is_category’ is closed to new replies.