WordPress.org

Ready to get started?Download WordPress

Forums

Giving echo'd content a class? (3 posts)

  1. dgissen
    Member
    Posted 10 months ago #

    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().
    
     }
     }
     }
     }
     }
    
    ?>
  2. alchymyth
    Forum Moderator
    Posted 10 months ago #

    you need to use a html element and a css class;

    one possible example:

    echo '<span class="whatever">' . $term->name . '</span>';
  3. dgissen
    Member
    Posted 10 months ago #

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

Reply

You must log in to post.

About this Topic