在帖子之间显示自定义 HTML Wordpress

Showing custom HTML between the posts Wordpress

我这里有点问题。 我想得到这个:

<div class="row">
    <div class="col-md-4"></div> <!-- WP post -->
    <div class="col-md-4"></div> <!-- WP post -->
    <div class="col-md-4"></div> <!-- WP post -->
</div>
<div class="row">
    <div class="col-md-4"></div> <!-- WP post -->
    <div class="col-md-4 CUSTOM ADD"></div> <!-- CUSTOM HTML FOR ADD -->
    <div class="col-md-4"></div> <!-- WP post -->
</div>
<div class="row">
    <div class="col-md-4"></div> <!-- WP post -->
    <div class="col-md-4"></div> <!-- WP post -->
    <div class="col-md-4"></div> <!-- WP post -->
</div>

或者这张图片可能更清楚: http://s11.postimg.org/5jqq7vuwj/example.jpg

我在此处找到了在网格中获取帖子的解决方案并对其进行了修改以显示我的自定义 html,但它没有:) 请帮忙!!!

我的代码是:(我很不擅长 php)。

<div class="container">
<?php 
    $count1 = 0 ;
    $count2 = 0 ;
    $count_posts = wp_count_posts( 'post' )->publish;
    $args = array( 'post_type' => 'post', 'posts_per_page' => 8, 'ignore_sticky_posts' => 0, 'post_status' => 'publish' );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <?php  $count2++ ?>

    <?php if ( $count2 >= 2 ) {
       $count1 = $count1 + 1 ; } ?>
    <?php if ( $count2 == 1 ) {
     echo '<div class="row">'; } elseif ( ( $count1 % 3 ) == 0 ) {
      echo '<div class="row">'; } ?>

    <div id="post-<?php the_ID(); ?>" class="<?php echo $postt = 'post-' ?><?php echo $count2 ?> col-sm-4" >
        <?php if($postt . $count2 === 'post-5') { 
        echo '<div class="col-md-4 reklama">';
        echo '<h1>ADD</h1>';
        echo '</div>';

       } else { ?>
        <header class="entry-header">       
            <h1 class="entry-title">
                <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
            </h1>
        </header><!-- .entry-header -->

            <div class="entry-content">  

        <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_title(); ?></a>

            </div><!-- .entry-imogin -->

        </div><!-- #post -->
        <?php } ?>
        <?php if ( $count2 % 3 == 0 ) {
         echo '</div>'; } 
        elseif ( $count_posts == $count2 ) { echo '</div>';} ?>
    <?php endwhile; ?>
    <p><?php the_posts_navigation(); ?></p>
</div><!-- #container -->

检查以下代码:

<div class="container">
<?php 

    $loopCounter = 0;

    $args = array( 'post_type' => 'post', 'posts_per_page' => 8, 'ignore_sticky_posts' => 0, 'post_status' => 'publish' );
    $loop = new WP_Query( $args );


    if($loop->have_posts()) : ?>
    <div class="row">
        <?php while($loop->have_posts()) : $loop->the_post(); $loopCounter++; ?>
            <?php if($loopCounter == 5) : $loopCounter++; ?>
                <div class="col-md-4 reklama"><h1>ADD</h1></div>
            <?php endif; ?>
            <div id="post-<?php the_ID(); ?>" class="<?php echo $postt = 'post-' ?><?php echo $count2 ?> col-md-4">
                <header class="entry-header">       
                    <h1 class="entry-title">
                        <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
                    </h1>
                </header><!-- .entry-header -->

                <div class="entry-content">  

                    <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_title(); ?></a>

                </div><!-- .entry-imogin -->

            </div><!-- #post -->

            <?php if($loopCounter % 3 == 0 ) : /*end running row and start new row*/ ?>
            </div><div class="row">
            <?php endif; ?>
        <?php endwhile; ?>
    </div>
    <?php endif; ?>
    <p><?php the_posts_navigation(); ?></p>
</div><!-- #container -->

逻辑是像往常一样保持循环运行并在循环内有条件地处理行列。