WordPress函数:comment_form_title 根据评论回复状态显示文本

江河/ 2023年06月01日/ WordPress/ 浏览 779

函数原型:


comment_form_title( string|false $no_reply_text = false, string|false $reply_text = false, bool $link_to_parent = true, int|WP_Post|null $post = null )


根据评论回复状态显示文本。仅影响禁用JavaScript的用户。


此函数会影响禁用Javascript的用户或未加载comment-reply.js Javascript的页面。


此函数通常直接在<div id=“response”>下方和评论表单之前使用。


参数说明:


$no_reply_text,不回复评论时要显示的文本。


$reply_text,回复评论时要显示的文本。接受“%s”作为回复评论的作者。


$link_to_parent,布尔值,用于控制将作者的姓名作为其评论的链接。


$post,显示评论表单的帖子。默认为当前全局职位。


函数源码:


function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true, $post = null ) {
	global $comment;

	if ( false === $no_reply_text ) {
		$no_reply_text = __( 'Leave a Reply' );
	}

	if ( false === $reply_text ) {
		/* translators: %s: Author of the comment being replied to. */
		$reply_text = __( 'Leave a Reply to %s' );
	}

	$post = get_post( $post );
	if ( ! $post ) {
		echo $no_reply_text;
		return;
	}

	$reply_to_id = _get_comment_reply_id( $post->ID );

	if ( 0 === $reply_to_id ) {
		echo $no_reply_text;
		return;
	}

	// Sets the global so that template tags can be used in the comment form.
	$comment = get_comment( $reply_to_id );

	if ( $link_to_parent ) {
		$author = '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $reply_to_id ) . '</a>';
	} else {
		$author = get_comment_author( $reply_to_id );
	}

	printf( $reply_text, $author );
}


使用举例:


<h3><?php comment_form_title(); ?></h3>

<h3><?php comment_form_title( __( 'Leave a Reply', 'textdomain' ), __( 'Leave a Reply to %s', 'textdomain' ) ); ?></h3>


发表评论

暂无评论,抢个沙发...

客服 工单