有很多wordpress都很羡慕别人能有彩色或是动态标签云,但是动态标签云一般都是使用flash插件,这样的话就不利于网站打开的速度和搜索引擎的优化,但是彩色标签云,何乐而不为呢?
今天我在这里就介绍下彩色标签云的应用,教会大家wordpress如何实现彩色标签云。
在自己的模板函数中加入如下代码:
有很多wordpress都很羡慕别人能有彩色或是动态标签云,但是动态标签云一般都是使用flash插件,这样的话就不利于网站打开的速度和搜索引擎的优化,但是彩色标签云,何乐而不为呢?
今天我在这里就介绍下彩色标签云的应用,教会大家wordpress如何实现彩色标签云。
在自己的模板函数中加入如下代码:
function colorCloud($text) {
$text = preg_replace_callback('|<a (.+?)>|i', 'colorCloudCallback', $text);
return $text;
}
function colorCloudCallback($matches) {
$text = $matches[1];
$color = dechex(rand(0,16777215));
$pattern = '/style=(\'|\")(.*)(\'|\")/i';
$text = preg_replace($pattern, "style=\"color:#{$color};$2;\"", $text);
return "<a $text>";
}
add_filter('wp_tag_cloud', 'colorCloud', 1);
位置如下代码所示:
<?php
include(TEMPLATEPATH."/js/breadcrumb-navigation-xt.php");
function wumii_get_related_items() {
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
$is_enabled = true;
global $post, $wumii_should_display;
$wumii_should_display = $is_enabled
&& !is_plugin_active('wumii-related-posts/wumii-related-posts.php') &&
get_post_status($post->ID) == 'publish' && get_post_type() == 'post' &&
empty($post->post_password) && !is_preview();
if (!$wumii_should_display) {
return;
}
$escapedUrl = wumii_html_escape(get_permalink());
$escapedTitle = wumii_html_escape(the_title('', '', false));
$escapedPic = wumii_html_escape(wumii_get_thumbnail_src());
echo <<<WUMII_HOOK
<div>
<input type="hidden" name="wurl" value="$escapedUrl" />
<input type="hidden" name="wtitle" value="$escapedTitle" />
<input type="hidden" name="wpic" value="$escapedPic" />
</div>
WUMII_HOOK;
}
function wumii_add_load_script($num = 4, $mode = 3) {
global $wumii_should_display;
if (!$wumii_should_display) {
return;
}
$sitePrefix = function_exists('home_url') ? home_url() : get_bloginfo('url');
$themeName = urlencode(get_current_theme());
echo <<< WUMII_SCRIPT
<p style="margin:0;padding:0;height:1px;">
<script type="text/javascript"><!--
var wumiiSitePrefix = "$sitePrefix";
var wumiiEnableCustomPos = true;
//--></script>
<script type="text/javascript"
src="http://widget.wumii.com/ext/relatedItemsWidget.htm?type=1&num=$num&mo
de=$mode&pf=WordPress&theme=$themeName"></script>
<a href="http://www.wumii.com/widget/relatedItems.htm" style="border:0;">
<img src="http://static.wumii.com/images/pixel.png" alt="无觅相关文章插件"
style="border:0;padding:0;margin:0;" />
</a>
</p>
WUMII_SCRIPT;
}
function wumii_html_escape($str) {
return htmlspecialchars(html_entity_decode($str, ENT_QUOTES, 'UTF-8'), ENT_QUOTES,
'UTF-8');
}
function wumii_get_thumbnail_src() {
global $post;
if ( get_post_meta($post->ID, 'thumbnail', true) ) {
$image_info = get_post_meta($post->ID, 'thumbnail', true);
return $image_info;
}
}if ( function_exists('register_sidebar') ){
register_sidebar(array(
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
}
function colorCloud($text) {
$text = preg_replace_callback('|<a (.+?)>|i', 'colorCloudCallback', $text);
return $text;
}
function colorCloudCallback($matches) {
$text = $matches[1];
$color = dechex(rand(0,16777215));
$pattern = '/style=(\'|\")(.*)(\'|\")/i';
$text = preg_replace($pattern, "style=\"color:#{$color};$2;\"", $text);
return "<a $text>";
}
add_filter('wp_tag_cloud', 'colorCloud', 1);function slider($before = '<li>', $after = '</li>') {
global $wpdb, $table_prefix;
$sql = "select ID,post_title,post_date from ". $table_prefix ."posts where post_status = 'publish' and post_type = 'post'and ID in (SELECT post_id FROM ". $table_prefix ."postmeta where meta_key = 'flash_img')";
$sql .= "ORDER BY post_date DESC LIMIT 5";
$posts = $wpdb->get_results($sql);
$output = '';
foreach ($posts as $post) {
$post_title = stripslashes($post->post_title);
$permalink = get_permalink($post->ID);
$thumbnail = get_post_meta($post->ID, 'flash_img', true);
$output .= $before . '<a href="' . $permalink . '" rel="bookmark" title="' . $post_title . '" target="_blank"><img src="' . $thumbnail . '" alt="' . $post_title . '" /></a>'. $after;
}
echo $output;
}function custom_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div>
<?php echo get_avatar($comment,$size='28',$default='<path_to_url>' ); ?>
<div>
<?php printf(__('<cite>%s</cite>'), get_comment_author_link()) ?> <?php edit_comment_link(__('(Edit)'),' ','') ?><br />
<em><?php printf(__('%1$s %2$s'), get_comment_date('Y/m/d '), get_comment_time(' H:i:s')) ?></em>
</div>
<div>
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em>您的评论正在审核中。_Your comment is being reviewed.</em>
<br />
<?php endif; ?><?php comment_text() ?>
</div><?php
}
?>
蚂蚁森林为我浇水吧!