繁体   English   中英

WordPress从某些类别中排除日期

[英]Wordpress exclude date from certain categories

我想在WordPress的特定类别中隐藏日期和时间。 我有下面的代码,这是每个页面显示的内容,并自动应用于每个类别。 这是我可以排除某些类别以停止显示日期信息的方式:

 <?php if(!in_category(60)):?>

此代码段仅允许我排除一个类别,但不适用于多个类别。

提前致谢!

if (have_posts()):

while(have_posts() ): the_post(); ?>
  <div align="center" class="blogimage">  <?php the_post_thumbnail( 'shop_single' ); ?>
   <h3><?php the_title(); ?></h3>
       <?php the_date(); ?>  
       <p> By </p>
         <?php the_author();?>
         </div>
    <p><?php the_content(); ?></p>

你可以这样使用

<?php 
    if(!check_in_category(60)):
?>

functions.php中添加此功能

check_in_category($categoryid){

    $categoryIdArr = array(60,62,85,90);
    if(in_array($categoryid,$categoryIdArr)){
        return true;
    }
    return false;
}

要么

<?php 
    if((!in_category(60)) || (!in_category(62))):
?>

像Vel的回答一样,我的第一个念头是使用“ in_array()”。 然而; in_category的编码表示in_category 应该适用于多个类别, in_category是它们以ID(或名称或子段)数组的形式传递。

$my_excluded_cats = array(60,62,85);
if ( ! in_category($my_excluded_cats) ) :
  // your code
endif; // as you're using if():

“此代码段仅允许我排除一个类别,但不适用于多个类别。”

如果这对您不起作用,则可能是由于变量作用域,即声明和分配数组的位置。 在这种情况下(使用示例代码)请尝试:

<h3><?php the_title(); ?></h3>
<?php 
  if ( ! in_category(array(60,62,85)) ) {
    the_date();
  }
?>  
<p> By </p>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM