我正在尝试显示一些自定义的帖子分类法术语-但每个术语都在各自特定的列表项中。
我有一个关于车库的网站。(在本地主机上开发,所以还没有链接)。
我有一个自定义的帖子类型,叫做Cars。在这里面,我有一个自定义的职位分类与汽车的制造‘福特’在这种情况下。
在‘福特’中是该汽车修理厂所有福特汽车的自定义后分类术语的列表。‘'GT','Sierra','Orion’。
而不是列出术语:'GT','Sierra','Orion‘。我想在ul列表中显示一张汽车的照片。
我已经创建了一个包含所有图像的sprite,并希望遍历这些图像来设置每个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 } ?>
发布于 2013-06-20 00:05:25
我解决了这个问题。以下是任何人的代码,谁正在寻找替换自定义后分类列表术语与个人图像,这是链接到术语存档。
源http://codex.wordpress.org/Function_Reference/get_term_link
<?php if ( get_post_type() == cars ) { ?>
<div class="entry-meta-custom">
<?php
$terms = get_terms('ford');
echo '<ul>';
foreach ($terms as $term) {
echo '<li class="'.$term->name.'"><a href="'.get_term_link($term->slug, 'ford').'"></a></li>';
}
echo '</ul>'; ?>
</div><!-- .entry-meta-custom -->
<?php } ?>
https://stackoverflow.com/questions/17192117
复制相似问题