kn007的个人博客
♥ You are here: Home > 软件与网络 > php > functions.php直接定义WordPress标签云

functions.php直接定义WordPress标签云

by | 8 Comments

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

之前有一篇文章是《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标签云

donate
有所帮助?

Comments

8 Comments立即评论
  1. LV3回复

    :x 单栏主题路过~

    1. MOD回复

      @大发: 嘿嘿,你那主题之前很多人用啊。。。挺简洁的

  2. 宁可华夏不长草,也要收复钓鱼岛。宁愿华夏遍地坟,也要杀光日本人!誓死保卫钓鱼岛!

  3. 回复

    这个挺实用的

  4. 回复

    :mrgreen: :mrgreen: 这代码可以不错!我使用的是我自己写的另一种冒充管理员留言功能,代码更少更方便!

    1. MOD回复

      @叫兽: 早就不用这个了。。。我直接在我做的AI里判断了。
      这个浪费查询,AI直接对post的数据做认证了。

    2. 回复

      @kn007: :x 你写的那个AJAX 评论分页异步加载文章,我还是学不会啊,不能教一半啊!快说奥秘 :x

  5. 回复

    :mrgreen: :mrgreen: 有些很多文章写的不错!很实用! :idea:

icon_wink.gificon_neutral.gificon_mad.gificon_twisted.gificon_smile.gificon_eek.gificon_sad.gificon_rolleyes.gificon_razz.gificon_redface.gificon_surprised.gificon_mrgreen.gificon_lol.gificon_idea.gificon_biggrin.gificon_evil.gificon_cry.gificon_cool.gificon_arrow.gificon_confused.gificon_question.gificon_exclaim.gif