Detailed explanation of the PHP function that calls comment templates and loops to output comments in WordPress, detailed explanation of wordpress_PHP tutorial

WBOY
Release: 2016-07-12 09:01:39
Original
955 people have browsed it

Detailed explanation of the PHP function in WordPress that calls comment templates and loops to output comments, detailed explanation of wordpress

comments_template
The comments_template function is a function that calls the comment template. It is very simple to use. Like get_header() and other functions, it is an include file class function. Today we will talk about its use.

Description
As mentioned above, it is a function that calls the comment template.

Use

 <&#63;php comments_template( $file, $separate_comments ); &#63;>
Copy after login

Which

$file is the file name to be called. Default value: /comments.php
$separate_comments Whether to separate comments of different types Boolean Default value: false
It’s quite general, please read below for more details

Usage examples

 <&#63;php comments_template(get_post_format().'-comment.php', true ); &#63;>
Copy after login

In this way, you can display article comments according to your different article types.
Is the usage somewhat similar to get_template_part()?
As for the exact meaning of $separate_comments, I didn’t understand it, but the official default theme has always been true, so I followed up. I have researched it before, and it seems that the type referred to here means whether to reply or not.

wp_list_comments
The wp_list_comments function is a function that loops to output each comment of the current article or page. It is mainly used to output each comment in the WordPress theme, saving us the pain of manual convenience, and also making the WordPress comment function very good. Modular.

The wp_list_comments function can be used in combination with the comments_template function in the theme to separate the comment function of WordPress, and can better control the number of comment nesting levels, the number of comments displayed on each page, comment styles, etc. . So if you want to do a good job on the theme, then take a look.

Description
Original English text:

Displays all comments for a post or Page based on a variety of parameters including ones set in the administration area.

My understanding:
Use a globally set parameter to display all comments on an article or page.

Usage

<&#63;php
   wp_list_comments( $args ); 
&#63;>
Copy after login

Parameter usage

<&#63;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' => ); &#63;>
Copy after login

$walker custom style class name
$avatar_size avatar size Default: 32
The $style comment container tag can be 'div', 'ol', or 'ul'. The default value is 'ul'. If not, you need to write it explicitly as follows.

<div class="commentlist"><&#63;php wp_list_comments(array('style' => 'div')); &#63;></div>
Copy after login

or

<ol class="commentlist"><&#63;php wp_list_comments(array('style' => 'ol')); &#63;></ol>
Copy after login

$type shows what kind of comments, parameters can be 'all', 'comment', 'trackback', 'pingback', 'pings'. 'pings' includes 'trackback' and 'pingback'.
Default value: ‘all’
$reply_text The text value of the reply button. This is rarely used and will not be explained. Default value: ‘Reply’
$login_text The text value of the login button. This is rarely used and will not be explained. Default value: ‘Log in to Reply’
$callback The callback function for comment display, that is, the function name for displaying the comment topic
$end-callback should be the callback function after the loop ends. I have not tested it, so please explore it yourself.
$reverse_top_level Boolean value. If this parameter is set to true, the latest comment will be displayed first, and subsequent comments will be displayed according to the background settings.
$reverse_children Boolean value. If this parameter is set to true, the latest comment with child comments will be displayed first, and subsequent comments will be displayed according to the background settings.
Example
Here is a demo of comment display in the official default theme twentyeleven,
For specific other parameters, please refer to the above introduction to demonstrate and explore by yourself.

<ol class="commentlist">
<&#63;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 函数在主题文件 "twentyeleven/functions.php"中定义。
&#63;>
</ol>

Copy after login

Articles you may be interested in:

  • Analysis of related functions used for title display in WordPress development
  • Analysis of related PHP functions used for debugging thumbnails in WordPress
  • Configure to solve the problem of WordPress paths not automatically adding slashes in Nginx server
  • The PHP function used to obtain the search form in WordPress uses parsing
  • Use the wp_count_posts function in WordPress to count articles Quantity
  • Detailed explanation of the use of classification function wp_list_categories in WordPress
  • WordPress restricts non-admin users to only comment once after an article
  • Detailed explanation of creating and adding filters in WordPress Related PHP functions
  • Detailed explanation of the usage of wp_title() function in WordPress development

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1088779.htmlTechArticleDetailed explanation of the PHP function in WordPress that calls comment templates and loops to output comments. Detailed explanation of wordpress comments_template comments_template function is a function that calls comment templates. The function is very easy to use...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template