当前位置: 编程技术>php
本页文章导读:
▪php 标签云效果(简单示例,入门参考) 分享一段php 标签云的实现代码。
代码:
<?php
/**
* php 标签云
*
* @package WNiaoBlog
*
* @subpackage Tag
*/
//Connect the database
//include('../include/config.php'); //加载配置文件
/**
* CountTag() - St.........
▪php 创建标签云的代码示例 php 标签云的创建代码一例,如下:
<?php
/**
* php 标签云效果
* edit: www.
*/
function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 30 )
{
$minimumCount = min( array_values( $data ) );
$maximumCount = max.........
▪Typecho 彩色标签云的实现代码 在Typecho中实现标签云的效果,在需要显示标签云的地方,添加如下代码:
代码示例:
<?php
Typecho_Widget::widget('Widget_Metas_Tag_Cloud')->to($tags); ?>
<?php if($tags->have()): ?>
<?php while .........
[1]php 标签云效果(简单示例,入门参考)
来源: 互联网 发布时间: 2013-12-24
分享一段php 标签云的实现代码。
代码:
<?php
/**
* php 标签云
*
* @package WNiaoBlog
*
* @subpackage Tag
*/
//Connect the database
//include('../include/config.php'); //加载配置文件
/**
* CountTag() - Statistics labels appear the number,and the data to be stored in the two array
*
* GetTag() - Access the Tag's Labels from the database
*/
function CountTag($String){
$TagString = $String;
//echo $TagString."
";
$Tags = explode(",",$TagString);
$n = 1;
$i = 0;
$Continue = TRUE;
//echo $Tags[1]."
";
//in case no-label's article
while($Tags[$n] OR $Tags[++$n] OR $Tags[++$n] ){
$EachTag = $Tags[$n++];
//echo $EachTag."
";
$Continue = TRUE;
for($i=0;$Continue;$i++){
if( $EachTagStr[$i][0] ) {
if( $EachTagStr[$i][0] == $EachTag ){
$EachTagStr[$i][1]++;
$Continue = FALSE;
}
else {
if( $EachTagStr[$i+1][0] ) $Continue = TRUE;
else {
$EachTagStr[$i+1][0] = $EachTag;
$EachTagStr[$i+1][1] = 1;
$Continue = FALSE;
}
}
} else { //initialize the array $EachTagStr[][]
$EachTagStr[$i][0] = $EachTag;
$EachTagStr[$i][1] = 1;
$Continue = FALSE;
}
}
}
return $EachTagStr;
}
function ShowTag($Row,$ablink){
$i = 0;
while($Row[$i][0]){
$EachTag = $Row[$i][0];
$EachCount = $Row[$i][1];
$Size = SetSize($EachCount);
echo " < a .$Size." ' onMouseOver=this.style.color='#900000'
onMouseOut=this.style.color='BLUE' href='".$ablink."tag?tag=".$EachTag."' target='_self' > ".$EachTag."(".$EachCount.")"." ";
$i++;
}
}
function GetTag(){
$QuerySet = mysql_query("select * from article");
while($Row = mysql_fetch_array($QuerySet)){
$Tag = $Row['tag'];
$TagString = $TagString.",".$Tag;
}
return $TagString;
}
function SetSize($Size){
$Size += 10;
if($Size > 30)
$Size = 30;
return $Size;
}
//Go
echo "
";
echo "标签云";
$String = GetTag();
$Row = CountTag($String);
ShowTag($Row,$ablink);
echo "
";
?>
[2]php 创建标签云的代码示例
来源: 互联网 发布时间: 2013-12-24
php 标签云的创建代码一例,如下:
<?php
/**
* php 标签云效果
* edit: www.
*/
function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 30 )
{
$minimumCount = min( array_values( $data ) );
$maximumCount = max( array_values( $data ) );
$spread = $maximumCount - $minimumCount;
$cloudHTML = '';
$cloudTags = array();
$spread == 0 && $spread = 1;
foreach( $data as $tag => $count )
{
$size = $minFontSize + ( $count - $minimumCount )
* ( $maxFontSize - $minFontSize ) / $spread;
$cloudTags[] = '<a . floor( $size ) . 'px'
. '" href="#" title="\'' . $tag .
'\' returned a count of ' . $count . '">'
. htmlspecialchars( stripslashes( $tag ) ) . '</a>';
}
return join( "\n", $cloudTags ) . "\n";
}
/*** Sample usage ***/
$arr = Array('Actionscript' => 35, 'Adobe' => 22, 'Array' => 44, 'Background' => 43,
'Blur' => 18, 'Canvas' => 33, 'Class' => 15, 'Color Palette' => 11, 'Crop' => 42,
'Delimiter' => 13, 'Depth' => 34, 'Design' => 8, 'Encode' => 12, 'Encryption' => 30,
'Extract' => 28, 'Filters' => 42);
echo getCloud($arr, 12, 36);
我收藏的一段php标签云的核心代码:
<?php
$artist = array("the roots","michael jackson","billy idol","more","and more","and_YET_MORE");
$count = array(5,3,9,1,1,3);
$highest = max($count);
for ((int) $x = 0; x < count($artist); $x++)
{
$normalized = $count[$x] / $highest;
$heading = ceil($normalized * 6); // 6 heading types
echo "<h".$heading.">".$artist[$x]."</h".$heading.">";
}
?>
[3]Typecho 彩色标签云的实现代码
来源: 互联网 发布时间: 2013-12-24
在Typecho中实现标签云的效果,在需要显示标签云的地方,添加如下代码:
代码示例:
<?php
Typecho_Widget::widget('Widget_Metas_Tag_Cloud')->to($tags); ?>
<?php if($tags->have()): ?>
<?php while ($tags->next()): ?>
<a href="/blog_article/</php $tags-/gt;permalink();/gt;.html">
<?php $tags->name(); ?></a> <?php endwhile; ?><?php endif; ?>
Typecho_Widget::widget('Widget_Metas_Tag_Cloud')->to($tags); ?>
<?php if($tags->have()): ?>
<?php while ($tags->next()): ?>
<a href="/blog_article/</php $tags-/gt;permalink();/gt;.html">
<?php $tags->name(); ?></a> <?php endwhile; ?><?php endif; ?>
若是单页面添加的标签云,则在page.php页面把
<?php $this->content(); ?>
替换为以下代码:
代码示例:
<?php if($this->slug=="tags"): ?><?php Typecho_Widget::widget('Widget_Metas_Tag_Cloud')->to($tags); ?><?php if($tags->have()): ?> <?php while ($tags->next()): ?> <a href="/blog_article/</php $tags-/gt;permalink();/gt;.html">
<?php $tags->name(); ?></a>
<?php endwhile; ?><?php endif; ?><?php else: ?><?php $this->content(); ?><?php endif; ?>
<?php $tags->name(); ?></a>
<?php endwhile; ?><?php endif; ?><?php else: ?><?php $this->content(); ?><?php endif; ?>
新建独立页面,缩略名为tags,即可在独立页面显示彩色标签云的效果了。
原理:
判断页面缩略为是否是tags,如果是则执行彩色标签云代码,如果不是则显示页面内容。
最新技术文章: