get_comment_link()
apply_filters( ‘get_comment_link’, string $link , WP_Comment $comment , array $args , int $cpage )
过滤器::过滤返回的单个注释permalink。
Filter Hook: Filters the returned single comment permalink.
说明(Description)
参数(Parameters)
参数 | 类型 | 说明 |
---|---|---|
$link | (string) | 注释permalink附加了“#comment-$id”。 |
$comment | (WP_Comment) | 当前注释对象。 |
$args | (array) | 重写默认值的参数数组。 |
$cpage | (int) | 计算出的“cpage”值。 |
源码(Source)
/** * Retrieve the link to a given comment. * * @since 1.5.0 * * @see get_page_of_comment() * * @global WP_Rewrite $wp_rewrite * @global bool $in_comment_loop * * @param mixed $comment Comment to retrieve. Default current comment. * @param array $args Optional. An array of arguments to override the defaults. * @return string The permalink to the given comment. */ function get_comment_link( $comment = null, $args = array() ) { global $wp_rewrite, $in_comment_loop; $comment = get_comment($comment); // Backwards compat if ( ! is_array( $args ) ) { $args = array( 'page' => $args ); } $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); $args = wp_parse_args( $args, $defaults ); if ( '' === $args['per_page'] && get_option('page_comments') ) $args['per_page'] = get_option('comments_per_page'); if ( empty($args['per_page']) ) { $args['per_page'] = 0; $args['page'] = 0; } if ( $args['per_page'] ) { if ( '' == $args['page'] ) $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args ); if ( $wp_rewrite->using_permalinks() ) $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . $wp_rewrite->comments_pagination_base . '-' . $args['page'], 'comment' ); else $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ); } else { $link = get_permalink( $comment->comment_post_ID ); } $link = $link . '#comment-' . $comment->comment_ID; /** * Filter the returned single comment permalink. * * @since 2.8.0 * * @see get_page_of_comment() * * @param string $link The comment permalink with '#comment-$id' appended. * @param object $comment The current comment object. * @param array $args An array of arguments to override the defaults. */ return apply_filters( 'get_comment_link', $link, $comment, $args ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.4.0 | wp-includes/comment-template.php:795 | 1 | 0 |
get_comment_link() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_comment_link/