Template structure

Question regarding template structure:

In a custom loop, I inserted a get_template_part(‘resources’, ‘layout’) which contains the following markup:

<div class=”custom-content”>
<?php if ( get_post_type() === ‘videos’ ) { ?>
<div class=”video-popup”>
<?php the_field(‘video_popup’); ?>
</div>
<?php } else { ?>
<div class=”featured-image”>
<?php the_post_thumbnail(‘full’); ?>
<?php if ( get_post_type() === ‘articles’ ) { ?>
<p class=”custom-content-btn”>
<a href=”<?php the_field( ‘article_link’ )?>” class=”btn btn-primary” target=”_blank”><?php echo __(‘READ’); ?></a>
</p>
<?php } ?>
</div>
<?php if ( get_post_type() === ‘audio’ ) { ?>
<div class=”audio-content”>
<?php the_field(‘audio_clip’); ?>
</div>
<?php } ?>
<?php } ?>
</div>

I have 3 CPT (videos, audio and articles). However I’m not sure if this is the best way to conditionally display the contents; seems a bit messy. I guess the tricky part is that there’s some markup that appears for all CPT, that’s sitting inbetween those conditional markups.

What would be considered the ‘best practice’ to tackle this? Appreciate any input!

Read more here:: Template structure

Leave a Reply

Your email address will not be published. Required fields are marked *