Detailed description of PHP functions that call comment templates and output comments cyclically in WordPress

Source: Internet
Author: User
Tags pings
This article mainly introduces the PHP functions used to call comment templates and circular output comments in WordPress. they are the comments_template function and the wp_list_comments function. For more information, see Comments_template
The comments_template function is a function that calls the comment template. it is easy to use. like functions such as get_header (), it is an include file function. let's talk about its usage today.

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

Use

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

Where

$ File: default file name to be called:/comments. php
$ Separate_comments: whether to separate non-use comment Boolean default value: false
The lecture is more general. For more details, see

Use instance

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

In this way, you can display the article comment based on your different article types.
Is the usage similar to get_template_part?
I didn't understand the exact meaning of $ separate_comments, but the official default theme is always true, so I followed up. I have studied it once before. it seems that the type here indicates whether to reply.

Wp_list_comments
The wp_list_comments function is a function that cyclically outputs each comment of the current article or page. it is mainly used to output each comment in the WordPress topic, saving us the trouble of manual convenience, the WordPress comment feature is also well modularized.

The wp_list_comments function can be used in combination with the comments_template function in the topic to independently comment on WordPress, in addition, the number of nested comment layers, the number of comments displayed on each page, and the comment style can be better controlled. So if you want to have a good theme, take a look.

Description
Original English:

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 set parameter to display all comments on an article or page.

Usage

<?php   wp_list_comments( $args ); ?>

Parameter usage

<?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 custom style class name
$ Avatar_size avatar size Default: 32
$ Style comment container labels can be 'P', 'ol ', or 'Ul'. the default value is 'Ul '. if not, you need to specify the label as follows.

<?php wp_list_comments(array('style' => 'p')); ?>

Or

 
 
    <?php wp_list_comments(array('style' => 'ol')); ?>

$ Type indicates the comment type, which can be 'all', 'comment', 'trackback', 'pingback', or 'pings '. 'pings 'includes 'trackback' and 'pingback '.
Default value: 'all'
$ Reply_text indicates the text value of the Reply button, which is rarely interpreted. default value: 'reply'
$ Login_text indicates the text value of the logon button. the default value is 'Log in to reply'
$ Callback: the callback function displayed in the comment, that is, the function name of the comment topic.
$ End-callback should be the callback function after the loop ends. I have not tested it. please explore it on your own.
$ Reverse_top_level: Boolean value. If this parameter is set to true, the latest comment is displayed first, and the comments that follow the background settings.
$ Reverse_children Boolean value. If this parameter is set to true, the latest comments with subcomments are displayed first, and subsequent comments are displayed in the background settings.
Instance
Here is a demonstration of the official default theme twentyeleven's comment display,
For details about other parameters, refer to the above description to demonstrate your exploration.

 
 
    <? 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_c The omment function is defined in the topic file "twentyeleven/functions. php".?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.