WordPress.org

Ready to get started?Download WordPress

Forums

Convert tags to class for a div (2 posts)

  1. tsnolan23
    Member
    Posted 1 year 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;
    					}
    			?>
                </div>
                </div>
    
    		<?php endwhile; ?>
    
        </div>

    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. alchymyth
    The Sweeper & Moderator
    Posted 1 year 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.

    http://codex.wordpress.org/Function_Reference/get_the_tags

Topic Closed

This topic has been closed to new replies.

About this Topic