WordPress主题开发:无评论不显示评论框

记录一次错误。

函数官方参考:

https://codex.wordpress.org/Function_Reference/have_comments

开发评论模板时遇到一个问题,当博文有评论时,一切正常,

WordPress主题开发:无评论不显示评论框

当博文无评论时,评论框不显示。

WordPress主题开发:无评论不显示评论框

原因:

是判断函数:have_comments()的问题

我在代码中是这样写的:

 if ( have_comments() ) : ?>



    


     comment_form(array(
    
        'comment_notes_after' => '
请访问我们的 隐私政策 页面。
',
        'title_reply'=>'添加新评论',
    //评论输入框上方文字
        'comment_notes_before'=>'
' . __( '' ) . ( $req ? $required_text : '' ) . '
',
    //评论输入框
        'comment_field' => '
' . _x( '', 'noun' ) . '
',
     

    
        'label_submit'=>__( '提交评论' ),
    //强制登陆留言
        'must_log_in'=>'
' .  sprintf( __( '您必须e登陆 才能留言.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '
',
    //登陆为
        'logged_in_as'=>'
' . sprintf( __( '当前身份为:%2$s,您需要退出吗?' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '
',
    ));
    
?>
    
    <h2 class="comments-title">
                printf( _nx( '一个想法 "%2$s"', '"%2$s"共有 %1$s 条评论  ', get_comments_number(), '注释标题', 'mirages' ),
                    number_format_i18n( get_comments_number() ), '' . get_the_title() . '' );
            ?>h2><ol class="comment-list">
                wp_list_comments( array(
                    'style'       => 'ol',
                    'short_ping'  => true,
                    'avatar_size' => 120,//头像大小
                    'reply_text'  =>'回复',/*回复文字*/
                    'callback' => 'mirages_comment'/*使用自定义回调函数控制评论的外观*/
                ) );
            ?>ol>
    

    <div class="pagination"> paginate_comments_links(); ?>
div>
    
    
 // Are there comments to navigate through?
            //是否有可浏览的注释?if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
        ?> endif; // Check for comment navigation(检查注释导航) ?>
    
  if ( ! comments_open() && get_comments_number() ) : ?><p class="no-comments"> _e( '评论已关闭.' , 'mirages' ); ?>p> endif; ?>


     endif; // have_comments() ?>


当博文中无评论时,函数判断为假,函数判断中的内容不显示。

当博文中有评论时,函数判断为真,显示判断中的内容。

在此处,这个函数是用来控制评论中的博文标题是否显示的,而我却在其中把评论框也包进去了。

应该是这样写:

 if ( have_comments() ) : ?>
	<h2 class="comments-title">
                printf( _nx( '一个想法 "%2$s"', '"%2$s"共有 %1$s 条评论  ', get_comments_number(), '注释标题', 'mirages' ),
                    number_format_i18n( get_comments_number() ), '' . get_the_title() . '' );
            ?>h2>
	 endif; // end have_comments() ?>
教程

B2主题日志页底部“赞”美化 - WordPress美化

2020-8-23 12:01:42

niRvana - 轻拟物wordpress主题更新记录

2020-1-8 4:06:00

⚠️
Npcink上的部份代码及教程来源于互联网,仅供网友学习交流,若您喜欢本文可附上原文链接随意转载。
无意侵害您的权益,请发送邮件至 1355471563#qq.com 或点击右侧 私信:Muze 反馈,我们将尽快处理。
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索