10 个实用的 WordPress 技巧教程
日前,网给大家介绍了《10 个简单的 WordPress 技巧》,无巧不成书,今天又在芒果小站看到《10 个实用的 WordPress 技巧教程》,下边我们一起来阅读一下吧。 1、自动向 WordPress 编辑器插入文本 <?php add_filter( 'default_content','my_editor_content' ); function my_editor_content( $content ) { $content = "芒果小站 - 这里不卖芒果,请另寻他处购买。"; return $content; } ?> 2、获取 WordPress 注册用户数量 $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo "总共有 ".$users." 位注册用户"; 3、根据指定自定义字段获取 WordPress 文章 <?php query_posts('meta_key=review_type&meta_value=movie'); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> 参数中 meta_key 是索要获取自定义字段名称,meta_value 是自定义字段取值。 <?php function filter_where($where = '') { $where .= " AND post_date >= '2009-01-01' AND post_date <= '2010-01-01'"; return $where; } add_filter('posts_where','filter_where'); query_posts($query_string); ?> 5、为某个 WordPress 标签生成 RSS 订阅源 <a href="http://www.mangguo.org/?feed=rss&tag=query_posts,loop"> 6、防止缓存 WordPress 样式文件 <link rel="stylesheet" href=http://www.mangguo.org/"<?php bloginfo('stylesheet_url'); echo '?'.filemtime( get_stylesheet_directory().'/style.css'); ?>" > 7、用户统计文章字数的 WordPress 函数 function wcount(){ ob_start(); the_content(); $content = ob_get_clean(); return sizeof(explode(” “,$content)); } 函数调用方法: <?php echo wcount(); ?> 8、禁止 WordPress 自动保存文章 function disableAutoSave(){ wp_deregister_script('autosave'); } add_action( 'wp_print_scripts','disableAutoSave' ); 9、告别 Pingbacks/h3> UPDATE `wp_posts` SET ping_status="closed"; 10、为 WordPress 文章插入作者信息 function get_author_bio ($content=''){ global $post; $post_author_name=get_the_author_meta("display_name"); $post_author_description=get_the_author_meta("description"); $html="<div class='clearfix' id='about_author'>"; $html.="<img width='80' height='80' class='avatar' src='http://www.gravatar.com/avatar.php?gravatar_id=".md5(get_the_author_email()). "&default=".urlencode($GLOBALS['defaultgravatar'])."&size=80&r=PG' alt='PG'/>"; $html.="<div class='author_text'>"; $html.="<h4>Author: <span>".$post_author_name."</span></h4>"; $html.= $post_author_description.""; $html.="</div>"; $html.="<div class='clear'></div>"; $content .= $html; return $content; } add_filter('the_content','get_author_bio'); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 在wordpress的feed中显示文章缩略图
- 允许WordPress指定文章/页面评论昵称/内容带连接地址
- Z-blog 首页顶部添加广告的简单方法
- WordPress手动修改文章排列顺序摆脱按发布时间升降序排列
- Wordpress:正在执行例行维护,请一分钟后回来,时间过长的解决
- WordPress新手安装教程(图文)
- WordPress使用函数wp_register_sidebar_widget添加随机文章
- WordPress打开速度非常慢的解决办法
- Limit Attempts by BestWebSoft – 限制用户登录尝试次
- WordPress多格式视频播放插件Easy Video Player教程