10 个实用的 WordPress 技巧教程

10 个实用的 WordPress 技巧教程,第1张

概述日前,网给大家介绍了《10 个简单的 WordPress 技巧》,无巧不成书,今天又在芒果小站看到《10 个实用的 WordPress 技巧教程》,下边我们一起来阅读一下吧。1、自动向 WordPress 编辑器插入文本 编辑当前主题目录的 functions.php 文件,并粘贴以下代码: <?php add_filter( 'default_content', …

日前,网给大家介绍了《10 个简单的 wordpress 技巧》,无巧不成书,今天又在芒果小站看到《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=http://www.mangguo.org/"<?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="<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'); 总结

以上是内存溢出为你收集整理的10 个实用的 WordPress 技巧教程全部内容,希望文章能够帮你解决10 个实用的 WordPress 技巧教程所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/1000631.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存