• I’ve been using the query (below) to output content on this page

    I want to give “$term->name” a class when it is echoed “echo $term->name”. I have not been able to do this, as I can’t seem to figure out how to frame $term->name with an html class. Any advice? Thanks.

    <?php
    
    $terms = get_terms('region');
    
    $count = count($terms);
    
     if ( $count > 0 )
     { foreach ( $terms as $term )
     {
    $args=array(
      'region' => $term->name,
      'country' =>$ter->name,
      'post_type' => 'producers',
      'post_status' => 'publish',
      'orderby'=>'title',
      'order'=>'ASC',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo  $term->name;
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
    	<?php get_template_part( 'content-archive' ); ?>
        <?php
    
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    
     }
     }
     }
     }
     }
    
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • you need to use a html element and a css class;

    one possible example:

    echo '<span class="whatever">' . $term->name . '</span>';
    Thread Starter dgissen

    (@dgissen)

    Thank you; I was missing the single-quotes and periods “.”
    !

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Giving echo'd content a class?’ is closed to new replies.