【发布时间】:2013-06-19 13:11:17
【问题描述】:
我正在尝试显示一些自定义帖子分类术语 - 但每个都在它们自己的特定列表项中。
我有一个关于车库的网站。 (在 localhost 上开发,所以还没有链接)。
我有一个名为 Cars 的自定义帖子类型。在这种情况下,我有一个自定义的帖子分类法,在这种情况下是汽车“福特”的品牌。
“福特”内是该车库中所有福特汽车的自定义后分类术语列表。 “GT”、“塞拉”、“猎户座”。
而不是列出术语:“GT”、“Sierra”、“Orion”。我想在 ul 列表中显示汽车的图片。
我已经创建了一个包含所有图像的精灵,并希望循环通过这些设置每个 li 项目的背景位置。
下面的第一批代码显示了一个条款列表,这些条款都很好,但不是我想要的。底部是我尝试添加列表项但只是得到一个空白屏幕的代码...
任何帮助,非常感谢。谢谢
<?php if ( get_post_type() == cars ) { ?>
<div class="entry-meta-custom">
<?php
$terms = get_the_terms( $post->ID, 'ford' );
if ( $terms && ! is_wp_error( $terms ) ) :
$draught_links = array();
foreach ( $terms as $term ) {
$draught_links[] = $term->name;
}
$on_draught = join( ", ", $draught_links );
?>
<?php echo $on_draught; ?>
<?php endif; ?>
</div><!-- .entry-meta-custom -->
<?php } ?>
这是我尝试添加列表项的地方。
<?php if ( get_post_type() == cars ) { ?>
<div class="entry-meta-custom">
<?php
$terms = get_the_terms( $post->ID, 'ford' );
if ( $terms && ! is_wp_error( $terms ) ) :
$draught_links = array();
foreach ( $terms as $term ) {
if ($term->name == 'gt') {
$term->name = '<li class="gt">' . $term->name . '</li>';
}
if ($term->name == 'sierra') {
$term->name = '<li class="sierra">' . $term->name . '</li>';
}
if ($term->name == 'orion') {
$term->name = '<li class="orion">' . $term->name . '</li>';
}
$draught_links[] = $term->name;
}
$on_draught = join( ", ", $draught_links );
?>
<?php echo '<ul>' . $on_draught . '</ul>; ?>
<?php endif; ?>
</div><!-- .entry-meta-custom -->
<?php } ?>
【问题讨论】:
标签: wordpress custom-post-type taxonomy taxonomy-terms