$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to use a custom comments template|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to use a custom comments template

matteradmin9PV0评论

My wordpress makes use of custom post templates. I'm now trying to create a custom comments template as well.

I noticed that the comments template is called via this function <?php comments_template( '', true ); ?>

I checked in my functions.php and comments.php but don't see the function being declared anywhere. Can someone please advise on how to go about introducing a custom comments template?

My wordpress makes use of custom post templates. I'm now trying to create a custom comments template as well.

I noticed that the comments template is called via this function <?php comments_template( '', true ); ?>

I checked in my functions.php and comments.php but don't see the function being declared anywhere. Can someone please advise on how to go about introducing a custom comments template?

Share Improve this question asked Oct 27, 2011 at 13:05 swordfish81swordfish81 5663 gold badges12 silver badges32 bronze badges 2
  • 1 @Chip Bennet, thanks for the heads up. Reading through that page, I notice that to set up an alternative comments template, i'd have to use this <?php comments_template( '/short-comments.php' ); ?> so am I right in assuming that I can start off by copy pasting the code from comments.php into short-comments.php and then work my way through from there? – swordfish81 Commented Oct 27, 2011 at 13:31
  • You can do it that way, but why? What are you trying to accomplish? – Chip Bennett Commented Oct 27, 2011 at 15:06
Add a comment  | 

2 Answers 2

Reset to default 2

The comments_template() template tag sets up the commenting variables and functions, and includes the comments.php template-part file. So, to create a custom comments template, use comments.php.

From there, you will need to get comfortable with the arguments, filters, and callbacks for wp_list_comments(), which is used to output the comment list, and comment_form(), which is used to output the comment-reply form.

You can use the callback function on wp_list_comments() function.

wp_list_comments();

Usually, you will find this line in comments.php file of your wordpress theme. And the output from this command is a pretty straightforward HTML structure.

Wordpress have a option of passing the callback function as an argument to wp_list_comments function.

This callback function should return the modified HTML structure of comments section, which we are looking to implement.

<ul class="comment-list comments">
    <?php
    wp_list_comments( array(
        'style'      => 'ul',
        'short_ping' => true,
            'callback' => 'better_comments'
    ) );
     ?>
</ul><!-- ment-list -->

You can check detailed tutorial here

https://www.5balloons.info/custom-html-for-comments-section-in-wordpress-theme/

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far