Convert tags to class for a div (2 posts)

  1. tsnolan23
    Posted 3 years ago #

    Is it possible to convert a posts tags to a div class? I have the following loop:

    <div class="results">
    		<?php query_posts('cat=3'); while(have_posts()): the_post(); ?>
                <div class="query">
                <b><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></b><br />
                <div class="tags"><img src="<?php bloginfo('stylesheet_directory');?>/images/tags.png" />
    			<?php  	$args = array(
    				'smallest'  => 8,
    				'largest'   => 22,
    				'unit'      => 'pt',
    				'number'    => 0,
    				'format'    => 'array', // important
    				'separator' => '\n',
    				'orderby'   => 'name',
    				'order'     => 'ASC',
    				'exclude'   => '',
    				'include'   => '',
    				'link'      => 'view',
    				'taxonomy'  => 'post_tag',
    				'echo'      => false );
    					$tag_list = wp_tag_cloud( $args );
    					$i = count($tag_list);
    					$sep = ', '; // enter your own seperator string
    					foreach($tag_list as $tags) {
    					echo strip_tags($tags);
    					if($i == 1) { continue; }; $i--; // don't show last sep after the list
    					echo $sep;
    		<?php endwhile; ?>

    The div that already has a class of query, I want the posts tags all to be listed as classes. Is that possible?

    Here is the site: http://wpdev.connectionsquad.com/fitness/workouts/

  2. Michael
    Forum Moderator
    Posted 3 years ago #

    I want the posts tags all to be listed as classes

    I'm not sure exactly what you mean by this.

    generally, you can use get_the_tags() and then use a 'foreach' loop to output what you need, possibly the tag slugs.


Topic Closed

This topic has been closed to new replies.

About this Topic