WordPress.org

Ready to get started?Download WordPress

Forums

Help with separate tags with get_the_tags (3 posts)

  1. toto
    Member
    Posted 6 years ago #

    Hello how can i make in there are more tags to be shown like thie: tag1, tag2, tag3
    I need to use this code

    <?php
    $posttags = get_the_tags('');
    if ($posttags) {
    foreach((get_the_category()) as $category)
    foreach($posttags as $tag) {
    echo ' <a href="?cat='.$category->cat_ID . '&tdo_tag=' . $tag->name . '">' . $tag->name . '</a>,' ;}
    }?>

    but how to separate each tag with comma?
    thanks for help

  2. producte
    Member
    Posted 6 years ago #

    $tags = get_the_tags($post->ID);
    					if($tags) :
    						foreach($tags as $tag) :
    							$sep = (empty($keywords)) ? '' : ', ';
    							$keywords .= $sep . $tag->name;
    							echo '<a href="http://www.site.com/blog/tag/'.$tag->name.'/" rel="tag">'.$tag->name.'</a>, ';
    						endforeach;
    					endif;

    Hope it helps.

  3. Cobalto
    Member
    Posted 6 years ago #

    Okay guy, but it shows the tags of the last post for every post with tags.
    Its strange.

    }elseif($btype == 'dynamictag' && (is_single())){
    			$tags = get_the_tags($post->ID);
    					if($tags) :
    						echo 'bb_keywords = "';
    						foreach($tags as $tag) :
    							$sep = (empty($keywords)) ? '' : ', ';
    							$keywords .= $sep . $tag->name;
    							echo $tag->name .', ';
    						endforeach;
    						echo '";';
    					endif;

Topic Closed

This topic has been closed to new replies.

About this Topic