在自定义post类型归档中,我试图将自定义分类术语slug作为css类添加到标记中。我设法让它输出页面->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 ) {
$terms = get_the_terms( $child_page->ID, \'media\' );
var_dump($terms);
echo \'<article class="post col \' . $terms->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>\';
}
?>