我在这里有一个标准的wordpress博客:http://webserver-meetandengage-com.m11e.net/insights/我创建了一个名为clients的新类别 .
此存档页面上的客户帖子将具有与标准博客帖子不同的元数据,因此我想要删除摘录,日期和作者等 .
为了达到这个目的,我尝试添加一个条件位代码,如果这个帖子区域的类别是'client',那么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>
但是包含它在这里打破了循环并且页面没有加载......我不确定我做错了什么,或者即使可能有更好的解决方案?
我基本上想要显示一组带有“客户”类别的帖子缩略图的元组,然后是博客中所有其他类别的另一组元素 .
我想它可能是IF类型的容器是客户端然后显示META1其他显示META2 .
任何帮助将非常感谢:)
3 回答
使用两个IF ELSE语句来实现此目的:
您需要在变量中设置它并回显变量 . 例如,如果客户端显示:none存储在$ style var中,如果没有,那么它不会放置样式
如果你想仅为客户改变样式,我建议你使用
<?php the_field('quote_name'); ?>
将你的div.card
添加为与类别相同的类(你可能还需要str_replace
和strtolower
来规范化类名),然后使用.card.client
应用CSS更改 .如果您不想显示HTML部分,请不要渲染它们 . 例如:
更好地使用类别的ID,因为稍后可以更改类别的名称 .