詳解WordPress中調(diào)用評論模板和循環(huán)輸出評論的PHP函數(shù)
comments_template
comments_template 函數(shù)是一個調(diào)用評論模板的函數(shù),使用起來很簡單,與get_header()等函數(shù)一樣,是一個include文件類函數(shù),今天來講一下他的使用。
描述
上面已經(jīng)講過了,就是調(diào)用評論模板的一個函數(shù)。
使用
<?php comments_template( $file, $separate_comments ); ?>
其中
$file 需要調(diào)用的文件名 默認(rèn)值: /comments.php
$separate_comments 是否分隔不用類型的評論 布爾型 默認(rèn)值: false
講的比較籠統(tǒng),更深層次請往下看
使用實(shí)例
<?php comments_template(get_post_format().'-comment.php', true ); ?>
這樣,就可以根據(jù)你不同的文章類型去顯示文章評論了。
用法上是不是跟get_template_part()有點(diǎn)類似呢?
至于$separate_comments準(zhǔn)確的意思,我也沒搞明白,不過官方默認(rèn)主題一直都是true的所以我也就跟進(jìn)了。之前研究過一次,貌似這里指的類型是是否回復(fù)的意思。
wp_list_comments
wp_list_comments 函數(shù)是一個循環(huán)輸出當(dāng)前文章或頁面每個評論的函數(shù),在 WordPress 主題中主要被用來輸出每一條評論,省去我們手工便利之苦,也把 WordPress 的評論功能很好的進(jìn)行了模塊化。
wp_list_comments函數(shù)在主題中配合comments_template函數(shù)聯(lián)合使用可以很好的將 WordPress 的評論功能獨(dú)立出來,而且可以更好對評論嵌套層數(shù)、每頁顯示評論數(shù)量、評論樣式等等等等進(jìn)行控制。所以如果你想做好主題的話,那還是看一下吧。
描述
英文原文:
Displays all comments for a post or Page based on a variety of parameters including ones set in the administration area.
我的理解:
用一個整體設(shè)置的參數(shù)來顯示一篇文章、頁面的所有評論。
用法
<?php wp_list_comments( $args ); ?>
參數(shù)使用
<?php $args = array( 'walker' => null, 'max_depth' => , 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => , 'per_page' => , 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => ); ?>
$walker 自定義樣式類名
$avatar_size 頭像大小 Default: 32
$style 評論容器標(biāo)簽可以是 ‘div', ‘ol', or ‘ul',默認(rèn)值是'ul',如果不是,那你需要像如下那樣明確寫出。
<div class="commentlist"><?php wp_list_comments(array('style' => 'div')); ?></div>
或
<ol class="commentlist"><?php wp_list_comments(array('style' => 'ol')); ?></ol>
$type 顯示何種評論,參數(shù)可以是 ‘a(chǎn)ll'、'comment'、'trackback'、'pingback'、'pings'. ‘pings' 包括'trackback' 和 ‘pingback'.
默認(rèn)值: ‘a(chǎn)ll'
$reply_text 回復(fù)按鈕的文本值,這個較少用不解釋 默認(rèn)值: ‘Reply'
$login_text 登錄按鈕的文本值,這個較少用不解釋 默認(rèn)值: ‘Log in to Reply'
$callback 評論顯示的回調(diào)函數(shù),即顯示評論主題的函數(shù)名稱
$end-callback 應(yīng)該是循環(huán)結(jié)束后的回調(diào)函數(shù),本人未實(shí)測,請自行探索。
$reverse_top_level 布爾值,如果設(shè)置本參數(shù)為真,則先顯示最新一條評論,后面的評論按照后臺設(shè)置顯示。
$reverse_children 布爾值,如果設(shè)置本參數(shù)為真,則先顯示最新一條有子評論的評論,后面的評論按照后臺設(shè)置顯示。
實(shí)例
這里是官方默認(rèn)主題 twentyeleven 中的評論顯示演示,
具體其他的參數(shù)請參照以上介紹自行演示探索。
<ol class="commentlist"> <?php /* Loop through and list the comments. Tell wp_list_comments() * to use twentyeleven_comment() to format the comments. * If you want to overload this in a child theme then you can * define twentyeleven_comment() and that will be used instead. * See twentyeleven_comment() in twentyeleven/functions.php for more. */ wp_list_comments( array( 'callback' => 'twentyeleven_comment' ) ); //twentyeleven_comment 函數(shù)在主題文件 "twentyeleven/functions.php"中定義。 ?> </ol>
相關(guān)文章
PHP下用rmdir實(shí)現(xiàn)刪除目錄的三種方法小結(jié)
PHP本身有一個rmdir()函數(shù)可以用來刪除目錄,不過要求必須是空目錄,本文列舉了三種方法。1、遞規(guī)法;2、系統(tǒng)調(diào)用法;3、循環(huán)法 。2008-04-04php讀取圖片內(nèi)容并輸出到瀏覽器的實(shí)現(xiàn)代碼
如果php以圖片,zip,exe等文件輸出到瀏覽器,而前面還輸出了其他字符,那就會是你看到的亂碼2013-08-08通用PHP動態(tài)生成靜態(tài)HTML網(wǎng)頁的代碼
最近研究PHP的一些開發(fā)技術(shù),發(fā)現(xiàn)PHP有很多ASP所沒有的優(yōu)秀功能,可以完成一些以前無法完成的功能,例如動態(tài)生成HTML靜態(tài)頁面,以減少服務(wù)器CPU的負(fù)載,提高用戶訪問的速度。2010-03-03php接口數(shù)據(jù)加密、解密、驗(yàn)證簽名
這篇文章主要介紹了php接口數(shù)據(jù)加密、解密、驗(yàn)證簽名的相關(guān)資料,需要的朋友可以參考下2015-03-03PHP CURL post數(shù)據(jù)報(bào)錯 failed creating formpost data
我們有時候用curl上傳文件遇到failed creating formpost data的錯誤,那具體是如何產(chǎn)生,又如何進(jìn)行處理解決呢,下面我們就來探討下2016-10-10配置php.ini實(shí)現(xiàn)PHP文件上傳功能
為大家介紹下在php.ini文件中配置php文件上傳功能的方法,涉及到一些重要的選項(xiàng),關(guān)系到php上傳文件大小的限制等,有需要的朋友參考下2014-11-11