在自定义post类型存档中,我试图将自定义分类法术语slug作为css类添加到标记中。我已经设法让它输出页面->ID,但努力得到$term->塞格工作。感觉我错过了一些很简单的东西。这里是完整的代码,感谢任何帮助:
<?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>';
}
?>
使用此函数get_the_terms( $id, $taxonomy )
只是传递它的post id在您的情况下'$parent_page-> id '和分类法的名称检索术语。例如:'category', 'post_tag', 'taxonomy slug'
它将返回一个对象,然后您可以使用(例如$result->slug
)访问段塞。