Hi!请登陆

wordpress评论模板调用函数comments_template()

2020-10-17 52 10/17

wordpress函数comments_template()的作用是加载评论模板,用于wordpress文章内容页面(包括自定义文章类型)或单页面,是wordpress模板制作中一个非常重要的函数。

函数代码:

1
<?php comments_template($file, $separate_comments);?>
参数说明:
  • $file – 字符串string,要加载的文件,可选,默认调用comments.php文件,路径/comments.php,位于主题根目录;
  • $separate_comments – 布尔值boolean,是否根据评论的类型划分评论,可选,默认false(否)

示例:

1、由于两个参数都是可选参数,可以直接使用,调用默认评论模板文件comments.php,代码如下:

1
<?php comments_template();?>

2、调用不同的评论模板文件,evaluate-comments.php文件保存在主题根目录,如果有两套评论显示样式就这样使用:

1
<?php comments_template('/evaluate-comments.php');?>

3、根据不同的文章类型显示文章评论:

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

函数位置:

comments_template()位于 wp-includes/comment-template.php

相关推荐