Jump to content

the tags in different color


bondigor69

Recommended Posts

hey guys what i'm trying to accomplish is show the post tags each in different background color.

what I got so far is this 2 pieces

<?php 
    
    $rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
    $color = '#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
    
?>


 <?php the_tags('Tags: ', ', ', '<br />'); ?> 
Link to comment
Share on other sites

You never said that in your first post, so I didn't know that

 

 

I dont use wordpress but try replacing <?php the_tags('Tags: ', ', ', '<br />'); ?> with

<?php 
$rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');

$tags = get_tags();
$html = '<div class="post_tags">';
foreach ( $tags as $tag ) {
	$tag_link = get_tag_link( $tag->term_id );

        $randColor = '#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
        $style = ' style="color: $randColor"';
			
	$html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'{$style}>";
	$html .= "{$tag->name}</a>";
}
$html .= '</div>';
echo $html;
?>

get_tags() reference code http://codex.wordpress.org/Function_Reference/get_tags

Edited by Ch0cu3r
Link to comment
Share on other sites

You never said that in your first post, so I didn't know that

 

 

I dont use wordpress but try replacing <?php the_tags('Tags: ', ', ', '<br />'); ?> with

<?php 
$rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');

$tags = get_tags();
$html = '<div class="post_tags">';
foreach ( $tags as $tag ) {
	$tag_link = get_tag_link( $tag->term_id );

        $randColor = '#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
        $style = ' style="color: $randColor"';
			
	$html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'{$style}>";
	$html .= "{$tag->name}</a>";
}
$html .= '</div>';
echo $html;
?>

get_tags() reference code http://codex.wordpress.org/Function_Reference/get_tags

It works but the color doesnt show. if I check the source. it prints out style="color: $randColor"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.