php - Wordpress | Custom post type loop with odd/even alternating

279

Cannot manage to create a custom post type loop with post alternating by the odd/even logic. What's wrong with the code?

 <div >

 <?php 

  $wpb_all_query = new WP_Query(array('post_type'=>'cesta', 'post_status'=>'publish', 'posts_per_page'=>-1)); ?>

  <?php if ( $wpb_all_query->have_posts() ) : ?>

   <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); if(($i % 2) == 0) : ?>

 <div >
  <h1><?php the_title(); ?></h1> 
  <?php the_content(); ?>
 </div>




 <?php else : ?>

 <div >
 <?php the_content(); ?>
 <h1><?php the_title(); ?></h1>
 </div>


  <?php endif; endwhile; endif; ?>

  </div>

People are also looking for solutions to the problem: php - Customizing add-to-cart messages based on the product IDs in WooCommerce 3

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.