国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Wordpress > 正文

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

2024-09-07 00:40:20
字體:
來源:轉載
供稿:網(wǎng)友

這篇文章主要介紹了WordPress中調用評論模板和循環(huán)輸出評論的PHP函數(shù),分別是comments_template函數(shù)與wp_list_comments函數(shù)的使用,需要的朋友可以參考下

comments_template

comments_template 函數(shù)是一個調用評論模板的函數(shù),使用起來很簡單,與get_header()等函數(shù)一樣,是一個include文件類函數(shù),今天來講一下他的使用。

描述

上面已經(jīng)講過了,就是調用評論模板的一個函數(shù)。

使用

<?php comments_template( $file, $separate_comments ); ?>

其中

$file 需要調用的文件名 默認值: /comments.php

$separate_comments 是否分隔不用類型的評論 布爾型 默認值: false

講的比較籠統(tǒng),更深層次請往下看

使用實例

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

這樣,就可以根據(jù)你不同的文章類型去顯示文章評論了。

用法上是不是跟get_template_part()有點類似呢?

至于$separate_comments準確的意思,我也沒搞明白,不過官方默認主題一直都是true的所以我也就跟進了。之前研究過一次,貌似這里指的類型是是否回復的意思。

wp_list_comments

wp_list_comments 函數(shù)是一個循環(huán)輸出當前文章或頁面每個評論的函數(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ù)來顯示一篇文章、頁面的所有評論。

用法

  1. <?php 
  2.    wp_list_comments( $args );  
  3. ?> 

參數(shù)使用

  1. <?php $args = array
  2.   'walker'      => null, 
  3.   'max_depth'     => , 
  4.   'style'       => 'ul'
  5.   'callback'     => null, 
  6.   'end-callback'   => null, 
  7.   'type'       => 'all'
  8.   'page'       => , 
  9.   'per_page'     => , 
  10.   'avatar_size'    => 32, 
  11.   'reverse_top_level' => null, 
  12.   '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ù)可以是 ‘all'、'comment'、'trackback'、'pingback'、'pings'. ‘pings' 包括'trackback' 和 ‘pingback'.

默認值: ‘all'

$reply_text 回復按鈕的文本值,這個較少用不解釋 默認值: ‘Reply'

$login_text 登錄按鈕的文本值,這個較少用不解釋 默認值: ‘Log in to Reply'

$callback 評論顯示的回調函數(shù),即顯示評論主題的函數(shù)名稱

$end-callback 應該是循環(huán)結束后的回調函數(shù),本人未實測,請自行探索。

$reverse_top_level 布爾值,如果設置本參數(shù)為真,則先顯示最新一條評論,后面的評論按照后臺設置顯示。

$reverse_children 布爾值,如果設置本參數(shù)為真,則先顯示最新一條有子評論的評論,后面的評論按照后臺設置顯示。

實例

這里是官方默認主題 twentyeleven 中的評論顯示演示,具體其他的參數(shù)請參照以上介紹自行演示探索。

  1. <ol class="commentlist"> 
  2. <?php 
  3.  /* Loop through and list the comments. Tell wp_list_comments() 
  4.  * to use twentyeleven_comment() to format the comments. 
  5.  * If you want to overload this in a child theme then you can 
  6.  * define twentyeleven_comment() and that will be used instead. 
  7.  * See twentyeleven_comment() in twentyeleven/functions.php for more. 
  8.  */ 
  9.  wp_list_comments( array( 'callback' => 'twentyeleven_comment' ) ); 
  10. //twentyeleven_comment 函數(shù)在主題文件 "twentyeleven/functions.php"中定義。 
  11. ?> 
  12. </ol>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 浠水县| 秀山| 许昌市| 兴安盟| 伊川县| 峡江县| 乐业县| 商丘市| 霍林郭勒市| 怀宁县| 斗六市| 广昌县| 祁东县| 左贡县| 石狮市| 昭通市| 孝感市| 田林县| 建德市| 青龙| 荔波县| 革吉县| 彩票| 太仆寺旗| 明星| 浪卡子县| 丽水市| 饶阳县| 平乐县| 宣化县| 婺源县| 大渡口区| 连江县| 长岛县| 福安市| 徐闻县| 抚顺市| 红河县| 方正县| 文山县| 新闻|