wordpress函数comments_template()

comments_template( string $file = ‘/comments.php’bool $separate_comments = false )

加载$file中指定的注释模板。
Loads the comment template specified in $file.

说明(Description)

如果不是在单个帖子或页面上,或者帖子没有评论,则不会显示评论模板。

使用WordPress数据库对象查询注释。注释通过“comments_array”过滤器钩子传递,钩子分别带有注释列表和post ID。

$file路径通过名为“commentsu template”的筛选器挂钩传递,该挂钩包括template path和$file的组合。首先尝试$filtered路径,如果失败,它将需要来自默认主题的默认注释模板。如果两者都不存在,则WordPress进程将停止。因此,建议不要删除默认主题。

如果帖子没有评论,将不会尝试获取评论。


参数(Parameters)

参数 类型 必填 说明
$file (string) 可选 要加载的文件。
$separate_comments (bool) 可选 是否按注释类型分隔注释。

返回(Return)

无返回值

源码(Source)

/**
 * Load 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.
 *
 * @uses $withcomments Will not try to get the comments if the post has none.
 *
 * @since 1.5.0
 *
 * @global WP_Query $wp_query
 * @global WP_Post  $post
 * @global wpdb     $wpdb
 * @global int      $id
 * @global object   $comment
 * @global string   $user_login
 * @global int      $user_ID
 * @global string   $user_identity
 * @global bool     $overridden_cpage
 *
 * @param string $file              Optional. The file to load. Default '/comments.php'.
 * @param bool   $separate_comments Optional. Whether to separate the comments by comment type.
 *                                  Default false.
 */
function comments_template( $file = '/comments.php', $separate_comments = false ) {
    global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
 
    if ( !(is_single() || is_page() || $withcomments) || empty($post) )
        return;
 
    if ( empty($file) )
        $file = '/comments.php';
 
    $req = get_option('require_name_email');
 
    /*
     * Comment author information fetched from the comment cookies.
     */
    $commenter = wp_get_current_commenter();
 
    /*
     * The name of the current comment author escaped for use in attributes.
     * Escaped by sanitize_comment_cookies().
     */
    $comment_author = $commenter['comment_author'];
 
    /*
     * The email address of the current comment author escaped for use in attributes.
     * Escaped by sanitize_comment_cookies().
     */
    $comment_author_email = $commenter['comment_author_email'];
 
    /*
     * The url of the current comment author escaped for use in attributes.
     */
    $comment_author_url = esc_url($commenter['comment_author_url']);
 
    $comment_args = array(
        'order'   => 'ASC',
        'orderby' => 'comment_date_gmt',
        'status'  => 'approve',
        'post_id' => $post->ID,
    );
 
    if ( $user_ID ) {
        $comment_args['include_unapproved'] = array( $user_ID );
    } elseif ( ! empty( $comment_author_email ) ) {
        $comment_args['include_unapproved'] = array( $comment_author_email );
    }
 
    $comments = get_comments( $comment_args );
 
    /**
     * Filter the comments array.
     *
     * @since 2.1.0
     *
     * @param array $comments Array of comments supplied to the comments template.
     * @param int   $post_ID  Post ID.
     */
    $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
    $comments = &$wp_query->comments;
    $wp_query->comment_count = count($wp_query->comments);
 
    if ( $separate_comments ) {
        $wp_query->comments_by_type = separate_comments($comments);
        $comments_by_type = &$wp_query->comments_by_type;
    }
 
    $overridden_cpage = false;
    if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
        set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
        $overridden_cpage = true;
    }
 
    if ( !defined('COMMENTS_TEMPLATE') )
        define('COMMENTS_TEMPLATE', true);
 
    $theme_template = STYLESHEETPATH . $file;
    /**
     * Filter the path to the theme template file used for the comments template.
     *
     * @since 1.5.1
     *
     * @param string $theme_template The path to the theme template file.
     */
    $include = apply_filters( 'comments_template', $theme_template );
    if ( file_exists( $include ) )
        require( $include );
    elseif ( file_exists( TEMPLATEPATH . $file ) )
        require( TEMPLATEPATH . $file );
    else // Backward compat code will be removed in a future release
        require( ABSPATH . WPINC . '/theme-compat/comments.php');
}
版权声明:原创作品,未经允许不得转载,否则将追究法律责任。
本站资源有的自互联网收集整理,如果侵犯了您的合法权益,请联系本站我们会及时删除。
本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。
本文链接:子佩工作室https://zptheme.com/5486.html
许可协议:《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权

本站分为普通会员,SVIP会员,永久会员。
SVIP会员新用户注册即送180天,到期后可邀请好友2位/180天进行无限续期。
永久会员支持微信支付在线开通。

积分是本站通用虚拟货币,可用于文章资源购买。
每天签到,评论或点赞文章,或者投稿都可免费获得积分
新用户注册免费赠送2积分 邀请用户注册2位/2积分

如果您已经成功付款但是网站没有弹出成功提示,请联系售后提供付款信息为您处理

本站资源属于虚拟商品,具有可复制性,可传播性,一旦授予,不接受任何形式的退款、换货要求。请您在购买获取之前确认好 是您所需要的资源

需要效果图的,可以联系售后(右侧核保售后,扫码添加或者点击 加入我们-联系客服)。或者微信添加企业微信:子佩工作室

计划书请提供费率条款(现价分红),100起。WP主题一般单个问题30起。主题二开500起,开发新主题3000起。低于1000须全款,其余先支付全款的60%,完成后支付余下的。

资源是指寿险计划书(定制除外),WP主题或插件不包含在永久会员之内!

发表回复