【发布时间】:2012-07-30 10:10:34
【问题描述】:
您好,我需要将此代码包装在一个函数中以供以后使用,我是 php 新手,请提供任何帮助
$term_slug = get_query_var( 'term' );
$taxonomyName = get_query_var( 'taxonomy' );
$current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
$args = array( 'child_of' => $current_term->term_id, 'hide_empty'=>false);
$terms = get_terms( 'tagportifolio', $args);
$assoc = taxonomy_image_plugin_get_associations();
if (!empty($terms)):
?>
<?php foreach( $terms as $child ): ?>
<?php if(array_key_exists( $child->term_taxonomy_id, $assoc )){echo wp_get_attachment_image( $assoc[$child->term_taxonomy_id], array(), false, 'thumbnail'); }
?>
<a href="<?php echo get_term_link( $child->name, $taxonomyName );?>">
<?php echo $child->name; ?></a ><br/>
<?php endforeach; ?>
<?php else: ?>
谢谢
【问题讨论】:
-
这不是 Stack Overflow 的工作方式。 Try something 第一。
-
而且仅供参考,您不必在每一行 PHP 代码中都需要
<?php和?>。