plugin development - Custom post type specific item design

Ihave a custom post type (benefits). Which as post name (bronze, silver, gold, diamond). All are listed in the same pa

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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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

相关推荐

  • plugin development - Custom post type specific item design

    Ihave a custom post type (benefits). Which as post name (bronze, silver, gold, diamond). All are listed in the same pa

    16小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信