title: How to wrap php code inside a function?
body: <p>Hi i need to wrap this code inside a function to use it later , i am php newbie any help please </p>
  
  <pre><code>$term_slug = get_query_var( 'term' );
  $taxonomyName = get_query_var( 'taxonomy' );
  $current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
  $args = array( 'child_of' =&gt; $current_term-&gt;term_id, 'hide_empty'=&gt;false);
  $terms = get_terms( 'tagportifolio', $args);
  $assoc = taxonomy_image_plugin_get_associations();
  
  if (!empty($terms)):
  ?&gt;
  
  &lt;?php foreach( $terms as $child ): ?&gt;
  &lt;?php if(array_key_exists( $child-&gt;term_taxonomy_id, $assoc )){echo wp_get_attachment_image( $assoc[$child-&gt;term_taxonomy_id], array(), false, 'thumbnail'); }
  ?&gt;
  &lt;a href="&lt;?php echo get_term_link( $child-&gt;name, $taxonomyName );?&gt;"&gt;
  &lt;?php echo $child-&gt;name; ?&gt;&lt;/a &gt;&lt;br/&gt;
  &lt;?php endforeach; ?&gt;
  &lt;?php else: ?&gt;
  </code></pre>
  
  <p>Thanks</p>