функция вывода рекламы в центре поста блокирует комментарии wordpress

343
01 августа 2017, 18:39

Есть страница в котором вот такой код:

<div class="post-banner random">
    <div class="row">
    <?php
    $posts1 = get_posts(array('post_type'=>'banner', 'orderby'=> rand, 'numberposts'=>2));
    $posts2 = get_posts(array('post_type'=>'post', 'orderby'=> rand, 'numberposts'=>1, 'category'=>-9, 'exclude'=>get_the_ID()));
    $posts = array_merge($posts1, $posts2);
    shuffle($posts);
    foreach($posts as $post) { ?>
        <div class="col-md-4">
            <div class="icerik-post">
                <?php
                if ($post->post_type == 'banner') {
                    ?>
                <div class="post-image">
                    <div class="img-block">
                        <a href="<?php echo (types_render_field( 'banner-url-adres')); ?>"><?php echo (types_render_field( 'banner-image')); ?></a>
                    </div>
                </div>
                <div class="post-icerik">
                    <h5 class="post-title"><a href="<?php echo(types_render_field( 'banner-url-adres')); ?>"><?php the_title() ?></a></h5>
                    <div class="info">
                        <p><span class="ago"><i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' önce '; ?></span></p>
                    </div>
                </div>
                    <?php
                }
                ?>
                <?php
                if ($post->post_type == 'post') {
                    ?>
                <div class="post-image">
                    <div class="img-block">
                        <a href="<?php the_permalink() ?>"><?php echo get_the_post_thumbnail() ?></a>
                    </div>
                </div>
                <div class="post-icerik">
                    <h5 class="post-title"><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h5>
                    <div class="info">
                        <p><span class="ago"><i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' önce '; ?></span></p>
                    </div>
                </div>
                    <?php
                }
                ?>
            </div>
        </div>
    <?php } wp_reset_postdata(); ?>
    </div>
</div>

также существует еще один такой же код(с косметическим изменением):

<div class="post-banner random-mini">
    <div class="row">
    <?php
    $posts3 = get_posts(array('post_type'=>'banner', 'orderby'=> rand, 'numberposts'=>1, 'exclude'=>get_the_ID()));
    $posts = array_merge($posts3);
    foreach($posts as $post) { ?>
        <div class="col-sm-12">
            <div class="icerik-post">
                <?php
                if ($post->post_type == 'banner') {
                    ?>
                <div class="post-image">
                    <div class="img-block">
                        <a href="<?php echo (types_render_field( 'banner-url-adres')); ?>"><?php echo (types_render_field( 'banner-image')); ?></a>
                    </div>
                </div>
                <div class="post-icerik">
                    <h5 class="post-title"><a href="<?php echo(types_render_field( 'banner-url-adres')); ?>"><?php the_title() ?></a></h5>
                    <div class="info">
                        <p><span class="ago"><i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' önce '; ?></span></p>
                    </div>
                </div>
                    <?php
                }
                ?>
                <?php
                if ($post->post_type == 'post') {
                    ?>
                <div class="post-image">
                    <div class="img-block">
                        <a href="<?php the_permalink() ?>"><?php echo get_the_post_thumbnail() ?></a>
                    </div>
                </div>
                <div class="post-icerik">
                    <h5 class="post-title"><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h5>
                    <div class="info">
                        <p><span class="ago"><i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' önce '; ?></span></p>
                    </div>
                </div>
                    <?php
                }
                ?>
            </div>
        </div>
    <?php } wp_reset_postdata(); ?>
    </div>
</div>

далее в function.php имеется код для вывода этих баннеров после определенного параграфа:

function childtheme_override_content() {
    $paragraphAfter =  2; //shows HTML after paragraph 7
    $content = apply_filters('the_content', get_the_content());
    $content = explode("</p>", $content);
    for ($i = 0; $i <count($content); $i++) {
    if ($i == $paragraphAfter) {
       get_template_part('parts/post-banner');
       get_template_part('parts/post-banner-mini');
    }
    echo $content[$i] . "</p>";
    }
}

Проблема заключается в том что, эта функция когда туда вставляю эти 2 страницы блокируют форму комментариев. Что делать?

привожу также пример страницы single.php

<?php get_header(); ?>
        <main>
            <div class="container">
                <div class="contant">
                    <div class="icerik">
                        <div class="row">
                            <div class="col-lg-9">
                                <div class="row">
                                    <div class="col-sm-12">
                                    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                                        <div class="icerik-post">
                                            <div class="col-sm-12">
                                                <h3 class="post-title"><?php the_title() ?></h3>
                                                <div class="breadcrumb-block">
                                                    <div class="row">
                                                        <div class="col-sm-6">
                                                            <ol class="breadcrumb">
                                                                <?php
                                                                    the_breadcrumb();
                                                                ?>
                                                            </ol>
                                                        </div>
                                                        <div class="col-sm-6">
                                                            <div class="info clearfix">
                                                                <p><span class="ago"><i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' önce '; ?></span><span class="okuma"><i class="fa fa-eye" aria-hidden="true"></i> <?php echo getPostViews(get_the_ID()); ?></span></p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="author-block">
                                                    <div class="row">
                                                        <div class="col-sm-6">
                                                            <ul class="author">
                                                                <li><?php  $user_id = get_the_author_meta('ID');
                                                                    // Retrieve The Post's Author ID
                                                                        // Set the image size. Accepts all registered images sizes and array(int, int)
                                                                        $size = 'thumbnail';
                                                                        // Get the image URL using the author ID and image size params
                                                                        $imgURL = get_cupp_meta($user_id, $size);
                                                                        // Print the image on the page
                                                                        echo '<img src="'. $imgURL .'" alt="">'; ?></li>
                                                                <li>
                                                                    <h6><?php the_author_meta( "user_firstname" ); ?> <?php the_author_meta( "user_lastname" ); ?></h6>
                                                                    <p><?php the_author(); ?></p>
                                                                </li>
                                                            </ul>
                                                        </div>
                                                        <div class="col-sm-6">
                                                            <?php my_author_box(); ?>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="post-icerik post">
                                                    <?php childtheme_override_content(); ?>
                                                </div>
                                                    <?php echo crunchify_social_sharing_buttons($content); ?>
                                            </div>
                                        </div>
                                    <?php endwhile; ?>
                                    <?php else: ?>
                                    <?php endif; ?>
                                    </div>
                                </div>
                                <div class="random">
                                    <div class="row">
                                        <?php get_template_part('parts/slider-post'); ?>
                                    </div>
                                </div>
                                <div class="comments-block">
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <?php if (comments_open() || get_comments_number()) comments_template('', true); // если комментирование открыто - мы покажем список комментариев и форму, если закрыто, но кол-во комментов > 0 - покажем только список комментариев ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-3">
                            <?php get_sidebar(); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
<?php setPostViews(get_the_ID()); ?>
<?php get_footer(); ?>

П.С. если удалить из функции childtheme_override_content() вот эти строчки

get_template_part('parts/post-banner'); get_template_part('parts/post-banner-mini');

сама форма комментариев вместе с комментариями появляется.

также я добавил в файл comments.php в конец функцию wp_reset_postdata(); , после этого форма при обновлении страницы то появляется, то исчезает.

READ ALSO