2013-03-14 66 views
0

我需要使用类别名称作为H1的类,并且还需要排除类别2.所以我将下面的PHP代码拼凑在一起。它工作正常,除了文章丢失格式。我知道get_post_format()是什么格式的应用,但是当我添加它时,它似乎没有做任何事情。任何帮助将不胜感激,谢谢。获取文章格式

<?php while (have_posts()) : the_post(); 
    $excludedcats = array(2); 
    $count = 0; 
    $categories = get_the_category(); 
    foreach($categories as $category) 
    { 
     $count++; 
     if (!in_array($category->cat_ID, $excludedcats)) 
      { 
      echo '<h1 class="category-heading ' . sprintf(__("heading-%s"), $category->slug) . '" >'; 

      if($count != count($categories)) 
       { 
      echo " "; 
      } 

     } 
    } 
single_post_title(); 
echo '</h1>'; 
the_content(); 
?> 

回答

0

get_post_format()不适用格式;它只是返回帖子类型,然后您可以使用它来应用该格式。为了对不同的职位类型不同的格式,你可以做这样的事情:

<?php 
    get_template_part('content', get_post_format()); 
?> 

然后你需要另一个文件,content-[post-type-slug].php(如图像的帖子,该文件将被称为content-image.php),您显示帖子。您也可以在get_post_format()的返回值上使用switch语句,但可能会变得混乱。