Php Wordpress-隐藏特定类别中的博客元数据
我在这里有一个标准的wordpress博客:我还创建了一个新的类别,叫做客户 这个归档页面上的客户端文章将具有与标准博客文章不同的元数据,所以我想去掉摘录、日期和作者等 为了实现这一点,我尝试添加一段有条件的代码,如果这个帖子区域的类别是“client”,那么在div中echo style=“display:none;” 下面是我正在尝试的代码行:Php Wordpress-隐藏特定类别中的博客元数据,php,wordpress,loops,if-statement,Php,Wordpress,Loops,If Statement,我在这里有一个标准的wordpress博客:我还创建了一个新的类别,叫做客户 这个归档页面上的客户端文章将具有与标准博客文章不同的元数据,所以我想去掉摘录、日期和作者等 为了实现这一点,我尝试添加一段有条件的代码,如果这个帖子区域的类别是“client”,那么在div中echo style=“display:none;” 下面是我正在尝试的代码行: <p<?php if ( in_category( 'client' )) { echo 'style="display:none;"'
<p<?php if ( in_category( 'client' )) { echo 'style="display:none;"' }?>>This is not client</p>
如果您只想为客户端更改样式,我建议您将.card
作为一个类添加到您的div.card
中,作为使用
的类别的名称(您可能还需要stru替换和strtolower
来规范化类名),然后使用.card.client
来应用CSS更改
如果不想显示HTML部分,就不要渲染它们。例如:
<?php if ( !in_category( 'ID' )){
<p class="card-text"><?php the_excerpt(__('(more…)')); ?></p>
}?>
}?>
更好地使用类别的ID,因为类别的名称可以在以后更改。通过两条IF-ELSE语句实现了这一点:
<div class="container blog-card-container">
<div class="card-columns">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>">
<div class="card">
<!-- Image if loop =========================================== -->
<?php if ( in_category('14') ) : ?>
<div class="client-header-logo-card" style="background-color: <?php the_field('client_brand_colour'); ?>;">
<?php
$image = get_field('client_logo');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div>
<?php else: ?>
<div class="blog-thumb-container">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
</div>
<?php endif ?>
<!-- Meta Data if loop =========================================== -->
<div class="blog-clients-card-block">
<?php if ( in_category('14') ) : ?>
<p class="blog-cat-label"><?php the_category(', '); ?></p>
<h2><?php the_title(); ?></h2>
<?php if( get_field('quote') ): ?><p class="client-quote"><?php echo custom_field_excerpt(); ?></p><?php endif; ?>
<?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; ?>
<?php if( get_field('quote_position') ): ?><p class="client-position" style="color:<?php the_field('client_brand_colour'); ?>;"><?php the_field('quote_position'); ?></p><?php endif; ?>
<?php if( get_field('button_text') ): ?>
<a class="btn btn-sm btn-client-archive" href="<?php the_permalink(); ?>" style="background-color:<?php the_field('client_brand_colour'); ?>;" role="button"><?php the_field('button_text'); ?></a>
<?php endif; ?>
<?php if( get_field('video_url') ): ?>
<div class="embed-container">
<?php the_field('video_url'); ?>
</div>
<?php endif; ?>
<?php else: ?>
<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>
<?php endif ?>
</div>
</a>
</div>
|
您需要在变量中设置它并回显该变量。例如,如果$style变量中存储了client display:none,则不会放置样式
<?php
if(in_category('client')){$style = 'display:none;';} else {$style = '';}
?>
<p style="<?php echo $style; ?>">This is not client</p>
我不太明白。。。我不想仅仅更改样式,我想更改显示在框中的实际数据。
<?php
if(in_category('client')){$style = 'display:none;';} else {$style = '';}
?>
<p style="<?php echo $style; ?>">This is not client</p>