I’ve got a grid of blog posts and I want to style posts from a certain category in a different way to the rest of the posts.
My current archive.php is pulling the same template_part for all the posts in the grid, so i thought if i alter it making a rule so that if posts have the category ‘guest blog’ they pull a different template, then this would style the category differently in the grid, but it hasn’t worked. The code I’ve tried is below but it’s breaking the blog page entirely, could anyone please help?
<?php get_header(); ?>
<main role="main" class="site-page">
<div class="wrap">
<article role="contentinfo" class="site-content">
<?php echo '<h1>' . single_cat_title("", false) . '</h1>'; ?>
<?php if (have_posts()) : ?>
<div class="row">
<div class="col-6 ta-l"><?php getSearchResultsFromTo(); ?></div>
<div class="col-6 ta-r"><?php if (is_paginated){ paginate(); } ?></div>
</div>
<div class="resource_grid">
<?php while (have_posts()) : the_post(); ?>
<?php if ( in_category( 'guest-blog' ) ) : ?>
<?php get_template_part('_template-parts/content', 'search2'); ?>
<?php else : ?>
<?php get_template_part('_template-parts/content', 'search'); ?>
<?php endwhile; ?>
</div>
<?php else : ?>
<?php get_template_part('_template-parts/content', 'none'); ?>
<?php endif; ?>
</article>
</div>
</main>
<?php get_footer(); ?>