10 个适用的 WordPress 技巧教程 推荐珍藏

1、主动向 WordPress 编辑器拔出文本
编辑以后主标题录的 functions.php 文件,并粘贴以下代码:
 
<?php
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = "芒果小站 - 这里不卖芒果,请另寻他处购买。";
return $content;
}
?>

2、获取 WordPress 注册用户数量
经过简略的 SQL 语句,即可不便取得 WordPress 注册用户的数量:
 
$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
echo "总共有 ".$users." 位注册用户";

3、依据指定自定义字段获取 WordPress 文章
在 query_posts() 函数中传入自定义字段参数,即可获取对应文章列表:
 
<?php query_posts('meta_key=review_type&meta_value=movie'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

参数中 meta_key 是索要获取自定义字段称号,meta_value 是自定义字段取值。

4、获取某个工夫段的 WordPress 文章
编辑 index.php 文件,只要在循环体之前,增加以下代码即可。当然需求依据需求改换工夫段的设置:
 
<?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 订阅源
如你所见,标签能够经过逗号宰割,这样也能够获取多个标签的 RSS Feed 源:
<a href="http://www.mangguo.org/?feed=rss&tag=query_posts,loop">
6、避免缓存 WordPress 款式文件
经过效劳器端设置以避免客户端读取缓存文件:
 
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?'.filemtime( get_stylesheet_directory().'/style.css'); ?>" >

7、用户统计文章字数的 WordPress 函数
在以后主题的 functions.php 文件中粘贴以下代码:
 
function wcount(){
ob_start();
the_content();
$content = ob_get_clean();
return sizeof(explode(” “, $content));
}

函数调用办法:

<?php echo wcount(); ?>

8、制止 WordPress 主动保留文章
要禁用 WordPress 的主动保留性能,请编辑 functions.php 文件并增加以下代码:
 
function disableAutoSave(){
wp_deregister_script('autosave');
}
add_action( 'wp_print_scripts', 'disableAutoSave' );

9、辞别 Pingbacks/h3>
在 phpMyAdmin 中执行以下语句,一键搞定恶心的 Pingbacks 性能。

UPDATE `wp_posts` SET ping_status="closed";10、为 WordPress 文章拔出作者信息
编辑主题对应的 functions.php 文件并粘贴以下代码:
 
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="<p class='clearfix' id='about_author'>\n";
$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'/>\n";
$html.="<p class='author_text'>\n";
$html.="<h4>Author: <span>".$post_author_name."</span></h4>\n";
$html.= $post_author_description."\n";
$html.="</p>\n";
$html.="<p class='clear'></p>\n";
$content .= $html;
return $content;
}
add_filter('the_content', 'get_author_bio');

版权一切,转载请注明出处。芒果

以上就是安达网络工作室关于《10 个实用的 WordPress 技巧教程 推荐收藏》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: WordPress 技巧
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
几个优化WordPress中JavaScript加载体验的插件引见

WordPress 自身以及主题和插件通常需求加载一些 JavaScript 来完成某些非凡性能。为了最大限制地保障兼容性...

多个WordPress站点应用同一数据库的办法

尚未装置WordPress 在初始配置WordPress之前,将wp-config.php中的$table_prefix值(默许为wp_)修正为所需求...

教你完成WordPress博客的“预加载”性能

chrome阅读器为什么比普通的阅读器快呢?缘由是chrome阅读器给全副页面都弄了预加载性能。 目前可能还是有少...

wordpress装置进程中遇到中文乱码的解决办法

在装置wordpress的时分,依照外面的readme.html的步骤进行装置,然而在拜访wp-admin/install.php的时分就呈...

wordpress回复评论文字的修正办法

  WordPress主题教程之修正wordpress回复评论文字办法,首选需求建设个自定义的评论模板,而后经过调用此...

2015年收费WordPress主题推荐(国际精选)

Enews &ndash; 黑色CMS/Blog双模式WordPress主题 历经将近一个月的工夫,主题作者水冷眸将之首款主题命名为...

需求提交

客服服务