之前使用dux的時候有很多方便的功能涕烧,現(xiàn)在換主題了,之前有功能沒有了汗洒,那么我們就手動加上吧
WordPress內(nèi)容折疊
WordPress添加說說功能
WordPress添加內(nèi)容評論可見
WordPress添加go跳轉(zhuǎn)
內(nèi)容折疊功能
這個對優(yōu)化文章結(jié)構(gòu)還是很有用的
點擊下方按鈕查看演示及內(nèi)容
移植自dux议纯,但是缺少js,就去網(wǎng)上找了一下溢谤,解決瞻凤,順便美化了一下外觀。
dux原版風(fēng)格
鉆芒美化
一世杀、引用js鲫构,將以下代碼加入至主題目錄下的footer.php中
<script>/* 為wordpress主題添加“內(nèi)容展開/收縮”功能開始 */jQuery(document).ready(function(jQuery){jQuery('.collapseButton').click(function(){jQuery(this).parent().parent().find('.xContent').slideToggle('slow');});});/* 為wordpress主題添加“內(nèi)容展開/收縮”功能開始 */</script>
二丶將下方代碼添加至主題目錄下的functions.php中
// 文章頁添加展開收縮效果functionxcollapse($atts,$content=null){extract(shortcode_atts(array("title"=>""),$atts));return'
? ? <style>.xControl {
? ? font-size: 15px;
? ? font-weight: bold;
? ? padding: 5px 0;
? ? box-shadow:0 0 20px #d0d0d0;/* 陰影 */
? ? background-color: #FFFFFF;/* 背景顏色 */
? ? border-bottom: 2px solid #e74c3c;/* 邊 */
? ? transition: all 0.1s linear;
? ? text-align: center;
? ? border-radius: 0 0 5% 5%;
? ? border-radius:4px;
}
.xControl a{
text-decoration: none;
? ? display: block;
}</style>
<div style="margin: 0.5em 0;">
? ? <div class="xControl">
? ? <a href="javascript:void(0)" class="collapseButton xButton"> <i class="fa fa-toggle-on" aria-hidden="true"> </i><span class="xTitle">'.$title.'</span></a>
? ? <div style="clear: both;"></div>
? ? </div>
<div class="xContent" style="display: none;">'.$content.'</div>
</div>';}add_shortcode('collapse','xcollapse');
三丶給后臺添加展開/收縮快捷標(biāo)簽按鈕
添加至主題目錄下的functions.php
//添加展開/收縮快捷標(biāo)簽按鈕function appthemes_add_collapse() {?><scripttype="text/javascript">if(typeofQTags!='undefined'){QTags.addButton('collapse','展開/收縮按鈕','[collapse title="點擊展開 查看更多"]','[/collapse]');}</script><?php}add_action('admin_print_footer_scripts','appthemes_add_collapse');
使用方法
文章編輯器中選擇文本,單擊展開/收縮按鈕玫坛,輸入要折疊的內(nèi)容,然后再次點擊展開/收縮按鈕包晰。會自動添加折疊結(jié)束標(biāo)簽湿镀。
添加說說功能
類似于qq空間的動態(tài),可以發(fā)一些雞毛蒜皮的小動態(tài)
把下邊的代碼加入到當(dāng)前主題的functions.php 中
可能剛加上查看說說界面404伐憾,去設(shè)置-固定鏈接更新一下就好了
//說說功能functionmy_custom_shuoshuo_init(){$labels=array('name'=>'說說','singular_name'=>'說說','all_items'=>'所有說說','add_new'=>'發(fā)表說說','add_new_item'=>'撰寫新說說','edit_item'=>'編輯說說','new_item'=>'新說說','view_item'=>'查看說說','search_items'=>'搜索說說','not_found'=>'暫無說說','not_found_in_trash'=>'沒有已遺棄的說說','parent_item_colon'=>'','menu_name'=>'說說');$args=array('labels'=>$labels,'public'=>true,'publicly_queryable'=>true,'show_ui'=>true,'show_in_menu'=>true,'query_var'=>true,'rewrite'=>true,'capability_type'=>'post','has_archive'=>true,'hierarchical'=>false,'menu_position'=>null,'supports'=>array('title','editor','author'));register_post_type('shuoshuo',$args);}add_action('init','my_custom_shuoshuo_init');
添加評論可見
把下邊的代碼加入到當(dāng)前主題的functions.php 中
評論后如果不顯示請查看是否開啟留言審核勉痴,審核通過后即可查看。
function reply_to_read($atts, $content=null) {? ? ? ? ? extract(shortcode_atts(array("notice" => '
get_results($query)) {? ? ? ? ? ? ? return do_shortcode($content);? ? ? ? ? } else {? ? ? ? ? ? ? return $notice;? ? ? ? ? }? ? ? }? ? add_shortcode('reply', 'reply_to_read');//添加評論可見快捷標(biāo)簽按鈕function appthemes_add_reply() {?><scripttype="text/javascript">if(typeofQTags!='undefined'){QTags.addButton('reply','評論可見按鈕','[reply]','[/reply]');}</script><?php}add_action('admin_print_footer_scripts','appthemes_add_reply');
添加go跳轉(zhuǎn)功能
它的作用主要是避免權(quán)重的流失树肃,畫面也可以很炫酷≌裘現(xiàn)在很多博客都帶有此功能。
如何添加設(shè)置go跳轉(zhuǎn)頁面胸嘴,可以參閱下邊這篇文章
wordpress 設(shè)置go跳轉(zhuǎn)頁面
自從用了DUX5.2后雏掠,文章內(nèi)的跳轉(zhuǎn)鏈接變成了go跳轉(zhuǎn),但之前并不了解這個東西劣像,所以之前文章內(nèi)的鏈接打開直接跳404乡话;,…
這里介紹如何給wordpress添加go跳轉(zhuǎn)功能>
把下邊的代碼加入到當(dāng)前主題的functions.php 中
//文章內(nèi)外鏈添加go跳轉(zhuǎn)functionthe_content_nofollow($content){preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);if($matches){foreach($matches[2]as$val){if(strpos($val,'://')!==false&&strpos($val,home_url())===false&&!preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){$content=str_replace("href=\"$val\"","href=\"".home_url()."/go/?url=$val\" ",$content);}}}return$content;}add_filter('the_content','the_content_nofollow',999);//評論者鏈接添加go跳轉(zhuǎn)functionadd_redirect_comment_link($text=''){$text=str_replace('href="','href="'.get_option('home').'/go/?url=',$text);return$text;}add_filter('get_comment_author_link','add_redirect_comment_link',5);add_filter('comment_text','add_redirect_comment_link',99);
文章源自鉆芒博客