簡體   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