I have a custom post type (benefits). Which as post name (bronze, silver, gold, diamond). All are listed in the same page template page-benefits.php. I want to display all on the same page but want to specific design for Diamond. how I can achieve this while remaining in the same loop and same page template.
I have a custom post type (benefits). Which as post name (bronze, silver, gold, diamond). All are listed in the same page template page-benefits.php. I want to display all on the same page but want to specific design for Diamond. how I can achieve this while remaining in the same loop and same page template.
Share Improve this question asked Jul 6, 2020 at 15:32 Sajjad HussainSajjad Hussain 1 1- It will be better if you include your page template code. Without seeing the code none will be able to help you. – Sabbir Hasan Commented Jul 6, 2020 at 18:02
1 Answer
Reset to default 0I think there are many ways to do so. Here is a simple solution for the loop-template:
<?php
// set css class, if post-title is 'diamond'
$cpt_class = ('diamond' === strtolower( $post->post_title ) ) ? 'post-is-diamond' : '';
?>
<!-- Begin loop-template -->
<article <?php post_class( $cpt_class ); ?> id="post-<?php the_ID(); ?>">
... your stuff here ...
</article>
So only if the post-title is 'diamond', the article has the css class 'post-is-diamond'.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742287700a4415623.html
评论列表(0条)