RUSSEL86

if/else conditional statement

Apr 27th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. //set condition for add Class first item
  2. ---------------------------------
  3. <?php  $ctr = 0;
  4. while ( $items->have_posts() ) :  $items->the_post();
  5. $class = $ctr == 0 ? ' active' : '';?>
  6. <?php echo $class; ?>
  7. <?php $ctr++;  
  8. endwhile;  ?>
  9.  
  10. or
  11. <?php if($id === 0): ?> active<?php endif; ?>
  12.  
  13.  
  14. //set condition for even post item
  15. --------------------------------------
  16. <?php  $idfst=0;
  17. if( have_rows('linha_de_produtos_content_area') ):
  18. while ( have_rows('linha_de_produtos_content_area') ) : the_row();
  19. if($idfst % 2 == 0) { ?>
  20. // your single item code here for even post show
  21. <?php }  $idfst++; endwhile; endif; ?>
  22.  
  23. //set condition for Odd post item
  24. ---------------------------------
  25. <?php  $idfst=1;
  26. if( have_rows('linha_de_produtos_content_area') ):
  27. while ( have_rows('linha_de_produtos_content_area') ) : the_row();
  28. if($idfst % 2 == 0) { ?>
  29. // your single item code here for Odd post show
  30. <?php }  $idfst++; endwhile; endif; ?>
  31.  
  32. //set condition for even and Odd post item
  33. ---------------------------------
  34. $count_posts = wp_count_posts();
  35. $published_posts = $count_posts->publish;
  36. if($published_posts % 2 == 0)
  37. {
  38.     // even
  39. }
  40. else
  41. {
  42.     //odd
  43. }
Advertisement
Add Comment
Please, Sign In to add comment