wordpress comments.php
时间 : 2023-12-30 00:15:02 声明: : 文章内容来自网络,不保证准确性,请自行甄别信息有效性
最佳答案
下面是一个简单的 Wordpress comments.php 模板的示例:
```php
<?php
/**
* The template for displaying comments.
*
* This is the template that displays the area of the page that contains both
* the current comments and the comment form.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Twenty_Twenty_One
* @since Twenty Twenty-One 1.0
*/
// If the current post is protected by a password and the visitor has not yet entered the password, return early.
if ( post_password_required() ) {
return;
}
?>
<div id="comments" class="comments-area">
<?php if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
$comments_number = get_comments_number();
if ( '1' === $comments_number ) {
/* translators: %s: post title */
printf( esc_html__( 'One comment on “%s”', 'twentytwentyone' ), get_the_title() );
} else {
printf(
/* translators: 1: number of comments, 2: post title */
esc_html( _nx( '%1$s comment on “%2$s”', '%1$s comments on “%2$s”', $comments_number, 'comments title', 'twentytwentyone' ) ),
number_format_i18n( $comments_number ),
get_the_title()
);
}
?>
</h2><!-- .comments-title -->
<ol class="comment-list">
<?php
wp_list_comments(
array(
'style' => 'ol',
'avatar_size'=> 60,
'short_ping' => true,
'reply_text' => __( 'Reply', 'twentytwentyone' ),
)
);
?>
</ol><!-- .comment-list -->
<?php endif; // Check for have_comments().
// If comments are closed and there are comments, let's leave a little note, shall we?
if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
?>
<p class="no-comments"><?php _e( 'Comments are closed.', 'twentytwentyone' ); ?>
<?php endif; ?>
<?php
comment_form(
array(
'logged_in_as' => null,
'title_reply' => __( 'Leave a Reply', 'twentytwentyone' ),
'title_reply_before'=> '<h2 id="reply-title" class="comment-reply-title">',
'title_reply_after' => '</h2>',
)
);
?>
</div><!-- #comments.comments-area -->
这个模板是用于在WordPress中显示文章评论的。它会根据评论的数量和状态来显示相应的内容。如果有评论,则会显示评论的数量和列表;如果评论被关闭,则会显示“评论已关闭”;如果用户已经登录,则显示评论表单。
你可以将这个代码片段复制到你的 Wordpress 主题的 comments.php 文件中,然后根据你的需要进行自定义和样式调整。
其他答案
WordPress comments.php文件是用于显示文章评论部分的模板文件。评论是网站上与读者互动最直接的方式之一,它可以让读者对文章进行讨论、提问或提供反馈意见。
在comments.php文件中,常见的元素包括评论内容、评论者头像、评论者名称、评论发表日期等。该文件负责对这些元素进行排版和格式化,并提供交互功能,如回复评论或对评论进行点赞。
comments.php文件通常使用WordPress的评论API来获取和显示评论。该API提供了一系列函数,如wp_list_comments()、get_comment_author()和get_comment_date()等,用于获取和显示评论的相关信息。
在comments.php文件中,你可以定义评论的样式和布局,可以根据需要修改评论区的外观和交互功能。你可以使用HTML和CSS来自定义评论区的结构和样式,也可以利用WordPress的评论模板标签来获取和显示评论的内容。
此外,comments.php文件还提供了一些钩子函数,如comment_form_before()和comment_form_after(),用于在评论表单前后插入额外的内容或功能。
总之,comments.php文件是WordPress中负责显示文章评论部分的模板文件,它负责获取、排版和显示评论内容,并提供与评论交互的功能。通过修改comments.php文件,你可以实现自定义的评论样式和交互方式,为用户提供更好的评论体验。
上一篇
帝国cms访问量插件下载
https/SSL证书广告优选IDC>>
推荐主题模板更多>>
推荐文章







