2016-12-29 100 views
0

我想呼應多個catgory,蛞蝓,而不是在一個WordPress環路的分類名在archive.phpWordPress的 - 回聲範疇,蛞蝓環

我的代碼看起來是這樣的,我嘗試了很多到目前爲止,但似乎沒有任何工作。所有我實現了接收一個類別的第一毛坯,但不是所有的人:

<li class="<?php the_category(' '); ?> "> 
     <div class="content"> 
      <h4><?php the_title(); ?></h4> 
     </div> 
    </li> 

回答

0

下面的代碼應該工作

<?php 
$categories = get_the_category(); 
$cls = ''; 

if (! empty($categories)) { 
    foreach ($categories as $cat) { 
    $cls .= $cat->slug . ' '; 
    } 
} 
?> 
<li class="<?php echo $cls; ?> "> 
    <div class="content"> 
     <h4><?php the_title(); ?></h4> 
    </div> 
</li> 
+0

像一個風情萬種!非常感謝你! – Nic