I want to take the basic WordPress loop and in the place where it makes the call for the content template, I want to run an if else statement that pulls in a different template part based on the category. I know I can make a bunch of copies of archive.php, but why do that for each and every single category you want to use?
So I tried this code, but it just pulled in the archive template in each case:
while ( have_posts() ) :
the_post();
if ( is_category( 'my-category-slug' )) {
get_template_part( 'template-parts/content', 'single' );
} else {
get_template_part( 'template-parts/content', 'archive' );
}
endwhile;
So can I even run an if else statement like this within the loop?
Aucun commentaire:
Enregistrer un commentaire