将WordPress自定义分类术语添加为css类

时间:2014-06-25 12:28:55

标签: css wordpress taxonomy

在自定义帖子类型存档上,我正在尝试将自定义分类术语slug作为css类添加到标记中。我设法让它输出page-> ID,但努力让$ term-> slug起作用。觉得我错过了一些非常简单的东西。这是完整的代码,感谢您的帮助:

     <?php

$parent_pages = get_pages( array( 'parent' => 0, 'post_type'=> 'archive', 'orderby' => 'menu_order' , 'order' => 'ASC', 'sort_column' => 'menu_order' ) );
foreach ( $parent_pages as $parent_page ) {


echo '<h1 class="page-heading" id="';
echo $parent_page->post_name;
echo '">';

echo $parent_page->post_title;
echo '</h1>';
 echo '<div class="wrapper grid4">';

$all_pages = get_pages(array( 'post_type'=> 'archive',  'orderby' => 'menu_order' , 'order' => 'ASC', 'sort_column' => 'menu_order' ) );
$child_pages = get_page_children($parent_page->ID, $all_pages );
foreach ( $child_pages as $child_page ) {
  echo '<article class="post col ' . $child_page->ID, $term->slug .'">';

 echo '<a class="fancybox" data-fancybox-type="iframe" href="http://www.iofpi.co.uk/civicworks.net/wp-content/plugins/pdfjs-viewer-shortcode/web/viewer.php?file=http://www.iofpi.co.uk/civicworks.net/wp-content/uploads/2014/05/Citizen_Manchester.pdf" title="' . the_title_attribute('echo=0') . '" >';

  echo get_the_post_thumbnail( $child_page->ID, 'medium');

  echo '</a>';


    echo '<h1>';
  echo $child_page->post_title;
  echo '</h1>';
  echo '</article>';
}
     echo '</div>';
  }
  ?>

1 个答案:

答案 0 :(得分:0)

使用此功能get_the_terms( $id, $taxonomy )只需在您的案例中传递帖子ID&#39; $ parent_page-&gt; ID&#39;以及从中检索术语的分类法的名称。例如:&#39; category&#39;,&#39; post_tag&#39;,&#39; taxonomy slug&#39;

它将返回一个对象,然后你可以访问slug,比如$result->slug