嗨,我需要将此代码包装在一个函数中以供以后使用,我是 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: ?>
谢谢