bondigor69 Posted October 25, 2013 Share Posted October 25, 2013 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 />'); ?> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 25, 2013 Share Posted October 25, 2013 Post tags for what exactly? Quote Link to comment Share on other sites More sharing options...
bondigor69 Posted October 25, 2013 Author Share Posted October 25, 2013 the actual post tags http://codex.wordpress.org/Function_Reference/the_tags Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 25, 2013 Share Posted October 25, 2013 (edited) the actual post tags http://codex.wordpress.org/Function_Reference/the_tags 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 October 25, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
bondigor69 Posted October 25, 2013 Author Share Posted October 25, 2013 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" Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 25, 2013 Share Posted October 25, 2013 (edited) Change $style = ' style="color: $randColor"'; to $style = ' style="color: '.$randColor.'"'; Edited October 25, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.