我已经创建了Custom post type \'references\' 下面有两个分类法
e、 g级
“”Custom Taxonomy A“具有类别”Cat-a1“,”Cat-a2“。。。。
“”Custom Taxonomy B“具有类别”Cat-b1“,”Cat-b2“。。。。
每个帖子或引用都分配了分类法A中的一个类别和分类法B中的一个类别。我有一个模板,用于在循环中显示上述自定义帖子类型中相对于自定义分类法A的帖子。G
标题“Cat-a1”
分配给此类别的所有职位
标题“Cat-a2”
分配给此类别的所有职位
我尝试的是从自定义分类法B中指定一个相关的类别名称作为每个标题的id
e、 g级
<div id="Catb1" ><h1>"Cata1"</h1>
ALL posts assigned to this category </div>
<div id="Catb2" ><h1>"Cata2"</h1>
ALL posts assigned to this category </div>
<div id="Catb3" ><h1>"Cata3"</h1>
ALL posts assigned to this category </div>
这是我的模板
<?php
$args=array(
\'post_type\' => \'references\',
\'child_of\' => 0,
\'parent\' => \'\',
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => 1,
\'hierarchical\' => 1,
\'exclude\' => \'\',
\'include\' => \'\',
\'number\' => \'\',
\'taxonomy\' => \'references-company\',
\'pad_counts\' => false
);
$categories=get_categories($args);
foreach ( $categories as $category ) {
if ( $category->parent > 0 ) {
continue;
}
$querystr = "SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->term_relationships, $wpdb->terms
WHERE term_id = (" . $category->cat_ID . ")
AND term_taxonomy_id = (" . $category->term_taxonomy_id . ")
AND ID = object_id
AND post_type = \'references\'
AND post_status = \'publish\'
ORDER BY post_date ASC";
$posts = $wpdb->get_results($querystr, OBJECT);
echo \'<div class="content_item" id="\';
$term_list = wp_get_post_terms($post->ID, \'references-industry\', array("fields" => "names"));
echo $term_list[0];
echo \'"><div class="border-r"><div class="quotesimg"><h1 class="termtitle headingopen" style="cursor: pointer;">\' . $category->name . \'(\' . $category->category_count . \')</h1></div></div>\';
echo \'<div class="references-inner textContent expander">\';
foreach ( $posts as $post ) {
setup_postdata($post);
echo \'<div class="floatleft twocol-one">\';
the_content();
the_excerpt();
echo \'<div class="social-linkedin">\';
$values = get_post_custom_values("linkedin");
if ( is_array($values) ) {
echo \'<a target="_blank" href="\';
echo the_field( "linkedin" );
echo \'"><img src="\';
echo get_template_directory_uri();
echo \'/images/ico_social_4.jpg" /></a>\';
} else {
echo \' \';
}
echo \'</div>\';
echo \'</div>\';
echo \'<div class="thumbnail-r fourcol-one last">\';
the_post_thumbnail(\'full\');
echo \'</div>\';
}
echo \'</div>\';
echo \'<div class="moreopen"><p class="more">Mere</p></div>\';
echo \'</div>\';
}
?>
如何从自定义分类法B中获取特定于post的术语/类别名称,以将它们用作div中的ID。我在上面的模板中进行了尝试,但似乎没有正确获取它们。
我用它来从分类法B中获得分配给post的术语名称
echo \'<div class="content_item" id="\'; $term_list = wp_get_post_terms($post->ID, \'references-industry\', array("fields" => "names")); echo $term_list[0]; echo \'">
谢谢