• Resolved pandabrand

    (@pandabrand)


    I have this template:

    <?php
    $args = array(
    'posts_per_page' => 12,
    'post_type' => 'post',
    'orderby' => 'rand'
    );
    $more_query = new WP_Query($args);
    if($more_query->have_posts()): $counter = 1; ?>
    <div class="row cc-row editorial__block">
      <?php while($more_query->have_posts()): $more_query->the_post(); ?>
        <?php get_template_part('layouts/card', 'card__3-1'); ?>
      <?php endwhile; ?>
    </div>
    <?php endif; ?>
    <?php wp_reset_query(); ?>

    which calls this template:

    <div class="col-4">
      <div class="card card__3-1">
        <a href="<?php echo the_permalink();?>" class="block__link"></a>
        <div class="card__image"  style="background-image:url('<?php echo the_post_thumbnail_url('large-feature'); ?>')"></div>
        <div class="card__category-block">
          <div class="<?php echo get_post_icon_class(); ?>"></div>
          <div class="card__category-block__category-details">
            <div class="card__category-block__category-type">
              <?php echo get_category_type_title();?>
            </div>
            <div class="card__category-block__category-info">
              <?php echo get_category_type_subject(); ?>
            </div>
          </div>
        </div>
        <div class="card__category-line"></div>
        <div class="card__filter"></div>
        <div class="card__body">
          <div class="card__copy">
            <div class="card__title">
              <?php echo get_card_title(); ?>
            </div>
            <div class="card__text">
              <?php echo get_card_excerpt(); ?>
            </div>
          </div>
        </div>
      </div>
    </div>
    

    The problem is after about the 4th or 5th element they start to nest into each other in the output. It’s never consistent sometimes it works mostly it doesn’t. How do implement this so it works.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    It sounds like your output might include shortcodes? It’s about the only explanation I can think of for “nesting” within a single loop. When this happens with shortcodes, the shortcode handler is written improperly, it is echoing or printing out content instead of collecting output and returning it.

    Or if not shortcodes specifically, one of the functions called where the return is echoed is actually echoing output within the call instead of returning it. The same thing as with shortcodes happens where the internal output is not coordinated with your output. When functions that echo content internally are not correctly coordinated with those that return content, a race condition develops and portions of output become misplaced.

    Thread Starter pandabrand

    (@pandabrand)

    Yeah, the get_card_excerpt function was pulling in HTML. I assumed it was plain text.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘loop starts to nest content randomly’ is closed to new replies.