May 8, 20179 yr Hello, I am working on a Wordpress website that is using custom taxonomies. I have found the following code to list taxonomies: <?php // Get terms for post $terms = get_the_terms( $post->ID , 'status' ); // Loop over each item since it's an array if ( $terms != null ){ foreach( $terms as $term ) { // Print the name method from $term which is an OBJECT print $term->slug ; print $term->name; // Get rid of the other data stored in the object, since it's not needed unset($term); } } ?> How my question is, how can I add html to this loop? I have tried multiple times but it either errors out, or it doesn't print the taxonomies. The desired result it to have the following markup: <button class="filter $term->slug" data-filter="$term->slug">$term->name</button> If anyone could help me, I would greatly appreciate it :-)
May 8, 20179 yr How about ... <?php // Get terms for post $terms = get_the_terms( $post->ID , 'status' ); // Loop over each item since it's an array if ( $terms != null ){ foreach( $terms as $term ) { ?> <button class="filter <?php print $term->slug; ?>" data-filter="<?php print $term->slug; ?>"><?php print $term->name; ?></button> print $term->slug ; <?php // Get rid of the other data stored in the object, since it's not needed unset($term); } } ?>
Create an account or sign in to comment