Make sure you are using the correct template file:
First, you need to make sure index.php
is being used as the template. You may install What The File Plugin, which will show what template file is being used at the top bar when you’re logged in.
Set the proper condition for portfolio
:
Once you are sure that index.php
is used as the template and you have template-parts/content-portfolio
file within your active theme, then you may use the following CODE for the get_post_type()
check to determine which template-part should be used:
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
if( get_post_type() === 'portfolio' ) :
get_template_part( 'template-parts/content', get_post_type() );
else :
get_template_part( 'template-parts/content', get_post_format() );
endif;
?>
<?php endwhile; ?>
Update: CODE swap based on comment:
Replace:
<?php
if ( has_post_format( array( 'gallery', 'video', 'image' ) ) ) {
get_template_part( 'template-parts/content', get_post_format() );
}
else {
get_template_part( 'template-parts/content', 'single' );
}
?>
with:
<?php
if( get_post_type() === 'portfolio' ) {
get_template_part( 'template-parts/content', get_post_type() );
}
else if ( has_post_format( array( 'gallery', 'video', 'image' ) ) ) {
get_template_part( 'template-parts/content', get_post_format() );
}
else {
get_template_part( 'template-parts/content', 'single' );
}
?>