【发布时间】:2018-06-26 14:46:56
【问题描述】:
我在这里有一个标准的 wordpress 博客:http://webserver-meetandengage-com.m11e.net/insights/,我创建了一个名为客户的新类别。
此存档页面上的客户帖子将具有与标准博客帖子不同的元数据,因此我想去掉摘录、日期和作者等。
为了实现这一点,我尝试添加一个条件代码,如果此帖子区域的类别是“客户端”,则 echo style="display:none;"在 div 里面。
这是我正在尝试的代码行:
<p<?php if ( in_category( 'client' )) { echo 'style="display:none;"' }?>>This is not client</p>
这是它出现的循环:
<div class="container blog-card-container">
<div class="row">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="col-md-4">
<a href="<?php the_permalink(); ?>">
<div class="card">
<div class="blog-thumb-container">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
</div>
<div class="blog-clients-card-block">
<?php if( get_field('quote_name') ): ?><p class="client-name" style="color:<?php the_field('client_brand_colour'); ?>;"><?php the_field('quote_name'); ?></p><?php endif; ?>
<p<?php if ( in_category( 'client' )) { echo 'style="display:none;"' }?>>This is not client</p>
<p class="blog-cat-label"><?php the_category(', '); ?></p>
<h2 class="blog-card-title"><?php the_title(); ?></h2>
<p class="card-text"><?php the_excerpt(__('(more…)')); ?></p>
<p><strong><?php the_author(); ?></strong> | <?php the_date(); ?> </p>
</div>
</div>
</a>
</div>
<?php understrap_pagination(); ?>
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>
</div>
但是在此处包含它会破坏循环并且页面无法加载...我不确定我做错了什么,或者即使可能有更好的解决方案?
我基本上想显示一组带有“客户”类别的帖子缩略图的元数据,然后为博客中的所有其他类别显示另一组元数据。
我猜它可能是如果容器的类别是客户端然后显示 META1 否则显示 META2。
任何帮助将不胜感激:)
【问题讨论】:
标签: php wordpress loops if-statement