Q
Q
Qleager2017-02-06 17:06:46
CMS
Qleager, 2017-02-06 17:06:46

How to wrap specific posts in a container in worpress?

<main id="content" class="site-content" role="main">
    <?php if ( have_posts() ) : ?>

      <?php /* The loop */ ?>

      <?php while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', get_post_format() ); ?>
      <?php endwhile; ?>
      
      <?php if ( get_next_posts_link() ) : ?>
      <span class="next-page" title="Показать ещё"><?php next_posts_link( __('') ); ?></span>
      <?php endif; ?>

    <?php else : ?>
      <?php get_template_part( 'content', 'none' ); ?>
    <?php endif; ?>

    </main>

You need to wrap some posts in divs, for example from 1 to 5; from 6 to 12;
How is it possible to do it exclusively in PHP

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2017-02-06
@Immortal_pony

<?php $iterator = 0; ?>
<?php while ( have_posts() ) : the_post(); ?>
    <?php if ($iterator < 12) { ?>
        <div class="<?= $iterator < 5 ? "one-to-five-class" : "six-to-twelve-class" ?>">
    <? php } ?>
        <?php get_template_part( 'content', get_post_format() ); ?>
    <?php if ($iterator < 12) { ?>
        </div>
    <?php } ?>
    <?php $iterator++; ?>
<?php endwhile; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question