in_category(() not working
-
Hi Michael and maybe others,
I saw the post that I responded in was [solved] so I made a new one:
I’m having problems with the
if ( in_category())
.In my archive.php the loop works perfect with the
if ( is_category())
, but I want to display this list of posts also on the single.php. This means I need to make a multiple loop with the<?php if (rewind_posts()) : ?>
function, and this seems to work. But it outputs the ‘Not Found’ message. It can’t seem to figure out which category the single post is in.Here is my code:
<?php if (rewind_posts()) : ?> <?php /* If this is in a category archive */ if (in_category()) { ?> <ul class="post"> <?php } ?> <?php while (have_posts()) : the_post(); ?> <li id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img width="45px" height="40px" src="<?php echo get_post_meta($post->ID, "Thumbnail", true);?>" /> </a> </li> <?php endwhile; ?> </ul> <?php else : ?> <h2 class="center">Not Found</h2> <?php include (TEMPLATEPATH . '/searchform.php'); ?> <?php endif; ?>
I have tried to put ‘4’ and ‘identity-design’ for example, also without the ( ‘ ) but no luck..
This is the code in archive.php that does work:
<?php if (have_posts()) : ?> <?php /* If this is a category archive */ if (is_category()) { ?> <ul class="post"> <?php } ?> <?php while (have_posts()) : the_post(); ?> <li id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img width="70px" height="70px" src="<?php echo get_post_meta($post->ID, "Thumbnail", true);?>" /> </a> </li> <?php endwhile; ?> </ul> <?php else : ?> <h2 class="center">Not Found</h2> <?php include (TEMPLATEPATH . '/searchform.php'); ?> <?php endif; ?>
Thank you very much in advance. Would mean a lot.
- The topic ‘in_category(() not working’ is closed to new replies.