最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解WordPress中調(diào)用評論模板和循環(huán)輸出評論的PHP函數(shù)

 更新時間:2016年01月05日 14:16:36   作者:稍息少年  
這篇文章主要介紹了WordPress中調(diào)用評論模板和循環(huán)輸出評論的PHP函數(shù),分別是comments_template函數(shù)與wp_list_comments函數(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)用的文件名 默認值: /comments.php
$separate_comments 是否分隔不用類型的評論 布爾型 默認值: false
講的比較籠統(tǒng),更深層次請往下看

使用實例

 <?php comments_template(get_post_format().'-comment.php', true ); ?>

這樣,就可以根據(jù)你不同的文章類型去顯示文章評論了。
用法上是不是跟get_template_part()有點類似呢?
至于$separate_comments準確的意思,我也沒搞明白,不過官方默認主題一直都是true的所以我也就跟進了。之前研究過一次,貌似這里指的類型是是否回復(fù)的意思。

wp_list_comments
wp_list_comments 函數(shù)是一個循環(huán)輸出當(dāng)前文章或頁面每個評論的函數(shù),在 WordPress 主題中主要被用來輸出每一條評論,省去我們手工便利之苦,也把 WordPress 的評論功能很好的進行了模塊化。

wp_list_comments函數(shù)在主題中配合comments_template函數(shù)聯(lián)合使用可以很好的將 WordPress 的評論功能獨立出來,而且可以更好對評論嵌套層數(shù)、每頁顯示評論數(shù)量、評論樣式等等等等進行控制。所以如果你想做好主題的話,那還是看一下吧。

描述
英文原文:

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 評論容器標簽可以是 ‘div', ‘ol', or ‘ul',默認值是'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'.
默認值: ‘a(chǎn)ll'
$reply_text 回復(fù)按鈕的文本值,這個較少用不解釋 默認值: ‘Reply'
$login_text 登錄按鈕的文本值,這個較少用不解釋 默認值: ‘Log in to Reply'
$callback 評論顯示的回調(diào)函數(shù),即顯示評論主題的函數(shù)名稱
$end-callback 應(yīng)該是循環(huán)結(jié)束后的回調(diào)函數(shù),本人未實測,請自行探索。
$reverse_top_level 布爾值,如果設(shè)置本參數(shù)為真,則先顯示最新一條評論,后面的評論按照后臺設(shè)置顯示。
$reverse_children 布爾值,如果設(shè)置本參數(shù)為真,則先顯示最新一條有子評論的評論,后面的評論按照后臺設(shè)置顯示。
實例
這里是官方默認主題 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)文章

最新評論

平安县| 陆良县| 延安市| 辉南县| 濉溪县| 辽宁省| 女性| 吴桥县| 吐鲁番市| 六盘水市| 安多县| 墨脱县| 荣昌县| 高要市| 乐安县| 高碑店市| 楚雄市| 黎川县| 九龙城区| 长寿区| 奈曼旗| 体育| 五指山市| 镇赉县| 东兰县| 西青区| 长寿区| 收藏| 大冶市| 元谋县| 丰镇市| 弋阳县| 寿宁县| 连平县| 南雄市| 上林县| 元谋县| 武胜县| 酒泉市| 泾川县| 仁寿县|