中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

實用的WordPress技巧教程

2019-10-10    來源:愛站科技

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

WordPress可以讓我們輕松進行自定義設置,而且不需要太多的編程知識,WordPress可用于個人或商業(yè)博客,是用于發(fā)布信息的最熱門平臺之一,那么下面我們就去看看實用的WordPress技巧教程。

1、自動向 WordPress 編輯器插入文本
編輯當前主題目錄的 functions.php 文件,并粘貼以下代碼:
?

復制代碼
代碼如下:

<?php
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = "芒果小站 - 這里不賣芒果,請另尋他處購買。";
return $content;
}
?>


2、獲取 WordPress 注冊用戶數(shù)量
通過簡單的 SQL 語句,即可方便獲得 WordPress 注冊用戶的數(shù)量:

?

?

復制代碼
代碼如下:

?

?


$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
echo "總共有 ".$users." 位注冊用戶";


3、根據(jù)指定自定義字段獲取 WordPress 文章
在 query_posts() 函數(shù)中傳入自定義字段參數(shù),即可獲取對應文章列表:

?

?

復制代碼
代碼如下:

?

?


<?php query_posts('meta_key=review_type&meta_value=movie'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>


參數(shù)中 meta_key 是索要獲取自定義字段名稱,meta_value 是自定義字段取值。

4、獲取某個時間段的 WordPress 文章
編輯 index.php 文件,只需在循環(huán)體之前,添加以下代碼即可。當然需要根據(jù)需要更換時間段的設置:

?

?

復制代碼
代碼如下:

?

?


<?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 >
6、防止緩存 WordPress 樣式文件
通過服務器端設置以防止客戶端讀取緩存文件:

?

?

復制代碼
代碼如下:

?

?


<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?'.filemtime( get_stylesheet_directory().'/style.css'); ?>" >


7、用戶統(tǒng)計文章字數(shù)的 WordPress 函數(shù)
在當前主題的 functions.php 文件中粘貼以下代碼:

?

?

復制代碼
代碼如下:

?

?


function wcount(){
ob_start();
the_content();
$content = ob_get_clean();
return sizeof(explode(” “, $content));
}


函數(shù)調(diào)用方法:

<?php echo wcount(); ?>

8、禁止 WordPress 自動保存文章
要禁用 WordPress 的自動保存功能,請編輯 functions.php 文件并添加以下代碼:

?

?

復制代碼
代碼如下:

?

?


function disableAutoSave(){
wp_deregister_script('autosave');
}
add_action( 'wp_print_scripts', 'disableAutoSave' );


9、告別 Pingbacks/h3>
在 phpMyAdmin 中執(zhí)行以下語句,一鍵搞定惡心的 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'>\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.="<div class='author_text'>\n";
$html.="<h4>Author: <span>".$post_author_name."</span></h4>\n";
$html.= $post_author_description."\n";
$html.="</div>\n";
$html.="<div class='clear'></div>\n";
$content .= $html;
return $content;
}
add_filter('the_content', 'get_author_bio');

實用的WordPress技巧教程就為大家介紹到這里了,如果你對WordPress的一些知識懂的越多,那么就越有助于管理你的博客和網(wǎng)站。

標簽: Wordpress

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:WordPress實現(xiàn)企業(yè)網(wǎng)站的方法

下一篇:找回WordPress后臺密碼的方法