WordPress函数:comment_author_url 当前评论作者的URL

江河/ 2023年05月27日/ WordPress/ 浏览 559

之前介绍过函数 comment_author_link,link 和 url 在这里的区别是:link是指 WordPress 站点中的作者页面-对应 author.php 模板文件。而 url 是指用户在评论文章时填写的站点地址。


如果 url 为空,则返回的数据和 get_comment_author 一致。


函数原型:


comment_author_url( int|WP_Comment $comment_id )


显示当前评论作者的URL。


$comment_id,WP_Comment或要打印作者IP地址的评论的ID。默认当前评论。


函数源码:


function comment_author_url( $comment_id = 0 ) {
	$comment    = get_comment( $comment_id );
	$author_url = get_comment_author_url( $comment );

	echo apply_filters( 'comment_url', $author_url, $comment->comment_ID );
}


使用举例:


<a href="<?php comment_author_url(); ?>">Visit  <?php comment_author(); ?>'s site</a>


if ( get_comment_author() == get_comment_author_link() ) {
	// 评论作者的url 是否存在
}


发表评论

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

客服 工单