functions.php直接定义WordPress标签云

提醒:本文最后更新于 3948 天前,文中所描述的信息可能已发生改变,请仔细核实。

之前有一篇文章是《WordPress添加彩色标签云并添加nofollow属性》,说的也是标签云,但是每次wordpress更新,我都要傻傻的去wp-includes/category-template.php去改大小和数量。。。奶奶的,坑爹啊。。。

所以这次3.4.2更新后,果断自己写了个函数放在functions.php里面hook,然后又果断发现baidu早有了。。。这贴算是个生活小记录吧。。。

function rbt_tag_cloud_filter($args) {
$args = array('smallest' => 8,'largest' => 20,'number' => 99);
return $args;
}
add_filter('widget_tag_cloud_args', 'rbt_tag_cloud_filter');

具体参数说明如下:

1. smallest – 定义标签的最小字号,默认为 8
2. largest – 定义标签的最大字号,默认为 22
3. unit – 设置字号类型,如 “pt” 或 “px” 等,默认为 “pt” 类型
4. number – 设置标签云数量,默认显示 45 个标签
5. orderby – 设置按 “name” 或 “count” 排序,默认为 “name” 方式
6. order – 设置按 “DESC” 或 “ASC” 升降序排列,默认为 “ASC” 升序
7. format – 显示方式 “list” 或 “float” 默认“float” 


另外,加了个新函数,防止冒名顶替者替我回复留言。。。

//防止冒充管理员留言
function checkauthor(){
  global $wpdb;
  $comment_author = ( isset($_POST['author']) ) ? trim(strip_tags($_POST['author'])) : null;
  $comment_author_email = ( isset($_POST['email']) )   ? trim($_POST['email']) : null;
  if(!$comment_author || !$comment_author_email){return;}
  $result_set = $wpdb->get_results("SELECT display_name, user_email FROM $wpdb->users WHERE display_name = '" . $comment_author . "' OR user_email = '" . $comment_author_email . "'");
  if ($result_set) {
      if ($result_set[0]->display_name == $comment_author){
          err( __('不能使用这个昵称回复!') );
      }else{
          err( __('不能使用该邮箱地址回复!') );
      }
  }
}
add_action('pre_comment_on_post', 'checkauthor');

转载请注明转自:kn007的个人博客的《functions.php直接定义WordPress标签云