看见wp的标签云的标签很多是根据标签数量来控制标签字体大小的主题,所以我想zblog php 也应该能实现,所以我就看wp的标签云的该段代码。所以整合到zblog php里去。写个函数就好了。函数如下:
function tqingxin_tags(){ global $zbp; $str = ''; $array = $zbp->GetTagList(array('*'),'',array('tag_Count'=>'DESC'),''); $counts = array(); foreach ( (array) $array as $key => $tag ) { $counts[ $key ] = $tag->Count; } $min_count = min( $counts ); $spread = max( $counts ) - $min_count; $largest=25; $smallest=8; if ( $spread <= 0 ) $spread = 1; $font_spread = $largest - $smallest; if ( $font_spread < 0 ) $font_spread = 1; $font_step = $font_spread / $spread; foreach ($array as $tag) { $zz= $smallest + ( ( $tag->Count - $min_count ) * $font_step ) ; $str .='<span style="font-size: '.$zz.'px;"><a href="'.$tag->Url.'" title="文章数:'.$tag->Count.'" target="_blank">'.$tag->Name.'</a></span> '; } return $str; }
前台调用:
{php}echo tqingxin_tags(){/php}
效果:
未经允许请勿转载:程序喵 » 【zblog php】标签云字体大小根据标签数量确定