如何在评论模板之外调用wp_list_Comments()?

时间:2012-02-16 作者:Richard B

我只是在页面中键入wp\\u list\\u comments()。php,但未显示任何内容。但是如果我将comments\\u template()标记放在那里,则会显示注释表单、注释和ping。为什么,为什么我不能在页面中使用wp\\u list\\u comments()。php?我会做错什么?

2 个回复
最合适的回答,由SO网友:Chip Bennett 整理而成

您需要通过以下方式包括评论功能comments_template(), 因为这个函数不仅仅包括comments.php, 文件,但也处理显示注释所需的所有查询和函数。

虽然the Codex doesn\'t really get into details, 你可以看到,by looking at source, 发生了什么:

<?php
/**
 * Loads the comment template specified in $file.
 *
 * Will not display the comments template if not on single post or page, or if
 * the post does not have comments.
 *
 * Uses the WordPress database object to query for the comments. The comments
 * are passed through the \'comments_array\' filter hook with the list of comments
 * and the post ID respectively.
 *
 * The $file path is passed through a filter hook called, \'comments_template\'
 * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
 * first and if it fails it will require the default comment template from the
 * default theme. If either does not exist, then the WordPress process will be
 * halted. It is advised for that reason, that the default theme is not deleted.
 *
 * @since 1.5.0
 * @global array $comment List of comment objects for the current post
 * @uses $wpdb
 * @uses $post
 * @uses $withcomments Will not try to get the comments if the post has none.
 *
 * @param string $file Optional, default \'/comments.php\'. The file to load
 * @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false.
 * @return null Returns null if no comments appear
 */
?>

SO网友:rexposadas

尝试将wp\\u list\\u comments()括起来,如下所示:

<ol class="commentlist">
<?php wp_list_comments();?>
</ol>
comments\\u template()只加载注释。php,它在一个封闭的CSS类中使用wp\\u list\\u注释。

HTH公司

结束

相关推荐

wp_list_pages by taxonomy?

我需要帮助为wp\\u list\\u类别创建一个助行器,该助行器可以过滤分类法,并在末尾元素中实际列出页面。我完全不知道该怎么办。我已经成功地为wp\\u list\\u pages函数实现了一个Walker,但这显然不适用于这种情况,因为我的wp\\u list\\u pages Walker依赖于子-父关系此外,我希望能够指定要返回的条款。基本上,我需要一个按分类法和术语筛选的列表。