Wordpress:评论不断显示在页面上

时间:2016-01-21 06:48:07

标签: php wordpress shortcode

我有这段代码来显示特定类别的帖子。它工作得很好,但问题是它一直显示下面的评论部分,我粘贴短代码。讨论:未选中允许评论。 请帮忙。 谢谢。

<?php
            function get_blog_post_category(){ 
            global $post;
            global $post_id;
            $content = "";
            $content .= '<div class="blog_post_wrap">';  
                    $content .= '<ul class="blog_post_ul">';  
                    $args = array( 'numberposts' => -1, 'category' => 10, 'orderby' =>   'date', 'order' => 'ASC', 'paged' => $paged );
                    $posts = get_posts( $args );
                       foreach( $posts as $post ): setup_postdata($post);

                        $content .= '<li class="col-md-3 blog_post_li">';   
                           $content .= '<a href="'.get_post_permalink().'">';  
                             $content .= '<div class="blog_single_post_wrap"> ';  

                                $post_image_id = get_post_thumbnail_id($post_to_use->ID);
                                if ($post_image_id) {
                                $thumbnail = wp_get_attachment_image_src( $post_image_id, 'post-thumbnail', false);
                                if ($thumbnail) (string)$thumbnail = $thumbnail[0];
                                }

                                $content .= '<div class="blog_image" style="background-image:url('.$thumbnail.')"></div>';

                                //$content .= '<div class="blog_post_images">' . get_the_post_thumbnail($post_id, 'thumbnail') . '</div>'; 
                                $content .= '<div class="blog_posting_wrap">';
                                $content .= '<div class="blog_time_date">' . get_the_time(get_option('date_format'));
                                $content .= '<span class="blog_viewed">' . getPostViews(get_the_ID()) . '</span>';
                                $content .= '</div>';                         
                                $content .= '<div class="blog_title">' . get_the_title() . '</div>';                         
                                $content .= '<div class="blog_expert">' .  get_the_excerpt() . '</div>';                                          
                                $content .= '</div>';
                              $content .= '</div>';  
                            $content .= '</a>';    
                        $content .= '</li>';

                    endforeach;
                    $content .= '</ul>';
            $content .= '</div>';
            return $content;
            }
             add_shortcode('iu_blog_posts_eng', 'get_blog_post_category');  


             ?>

1 个答案:

答案 0 :(得分:0)

取消选中允许评论不会让用户对将来的帖子发表评论,但在您更改设置之前,很少有帖子已过去,因此您需要手动更改comment_status,如下所示:

UPDATE wp_posts SET comment_status="closed";