Using in_category on search results page to customize the results
-
I’m working with numerous category templates that when viewed individually offer more or less information about posts within each of them.
I’ve stumped myself when it comes to carrying over those unique categorical displays to search results.
What I’m trying to do is say “if any of the results are in category X, call on these elements for it”. Or else, “if any of the results are in category y, display these other elements for only those ones”.
But I can’t seem to get this to work, so I wanted to ask the WordPress experts if this is possible?
A simplified example of my code is:
<?php $my_query = new WP_Query($query_string . "&posts_per_page=10"); while ($my_query->have_posts()) : $my_query->the_post(); if ( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); $do_not_duplicate = $post->ID; ?> <?php if (in_category('1')); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2 class="posttitle"> <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> </h2> <div class="postentry"> <?php the_excerpt(); ?> </div> <!-- <?php trackback_rdf(); ?> --> </div> <?php } elseif (in_category('7,8,9,10,11')); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2 class="posttitle"> <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> </h2> <span class="postmeta"><?php comments_number('no responses','one response','% responses'); ?></span> <!-- <?php trackback_rdf(); ?> --> </div> <?php endif; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Using in_category on search results page to customize the results’ is closed to new replies.