簡體   English   中英

Wordpress沒有顯示每個帖子的評論數

[英]Wordpress is not showing number of comments per post

所以我試圖使wordpress循環與每個帖子顯示nubmer評論。 我只想要一個類別的帖子。 循環正常,但注釋數量不正確。 在每個帖子上,只需說沒有評論(即使我在那里有10條或更多評論)

<?php
                $query = new WP_Query('category_name=blog&post_type=post');
                if ($query->have_posts()) :
                    ?>
                <?php
                    // Start the loop.
                while ($query->have_posts()) : $query->the_post();
?>
                <div class="col-12 col-md-6 blog_single_homepage">
                        <div class="col-12">
                            <div class="row align-items-end">
                                <div class="col-5 col-md-3 autor_section">

                                   <?php echo get_avatar( get_the_author_meta('user_email'), '150', $default, $alt, array( 'class' => array( 'rounded-circle' ) ) ); ?>
                                </div>
                                <div class="col-7 col-md-9 autor_info">
                                    <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>" class="autor_name"><?php the_author(); ?></a>
                                    <span class="align-middle"><?php the_time('d/m/Y'); ?></span>
                                    <div class="cat">
                                        <p><?php the_category(', '); ?></p>
                                    </div>
                                    <hr>
                                </div>
                            </div>
                        </div>
                        <div class="col-12 blog_content_short">
                            <a href="<?php the_permalink(); ?>">
                                <h3><?php the_title() ?></h3>
                                <p><?php echo wp_trim_words(get_the_content(), 50); ?></p>
                                <div class="read_more_over">
                                    <div class="title_inner">
                                        <?php the_title() ?>
                                    </div>
                                    <div class="inner_show">
                                        Read more
                                    </div>
                                </div>
                            </a>
                            <div class="comments">
                                <?php 
printf( _nx( 'One Comment', '%1$s Comments', get_comments_number(), 'comments title', 'textdomain' ), number_format_i18n( get_comments_number() ) );

?>
                            </div>
                        </div>
                    </div>
                <?php
                    // End the loop.
                endwhile;
                else :
                    echo 'No blog posts...';

                endif;
                ?>

您的代碼正常工作。 請驗證評論是否得到批准。 此代碼未顯示尚未批准的評論。 如果要獲取所有注釋的詳細信息,請使用wp_count_comments 這將返回有關每種狀態的注釋的詳細信息:在此處查看更多詳細信息: https : //codex.wordpress.org/Function_Reference/wp_count_comments

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM