• Resolved modeman

    (@modeman)


    Hello, i have this code https://pastebin.com/9Jgwihr7

    Now this code loop first 6 posts without starting <div class=”row”><div class=”movie_list”>

    and it’s breaks my template, maybe anybody knows how to correctly dot his counting?

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • your code is using php shorttags <? which are not understood by all servers;

    try with:

    <?php  if($i % 6 == 0) {echo '</div></div><div class="row"><div class="movie_list">'; ?>
                                     <?php } $i++; ?>
    Thread Starter modeman

    (@modeman)

    Nothing changes.

    Now it loop like this:

    <div class="container">
    <div class="col-md-2"></div>
    <div class="col-md-2"></div>
    <div class="col-md-2"></div>
    <div class="col-md-2"></div>
    <div class="col-md-2"></div>
    <div class="col-md-2"></div>
    </div>
    <div class="row"></div>
    <div class="row"></div>
    <div class="row"></div>

    It’s should be like this:

    <div class="container">
    <div class="row"></div>
    <div class="row"></div>
    <div class="row"></div>
    <div class="row"></div>
    </div>

    The 6 posts inside div row, now first 6 posts dont have div “row”, and last 3 div “row” is out off div “container”.

    I cannot reproduce you problem –
    I ran your code in my test site (local install) and the html structure shows as it should be; there is just one empty div too much at the end.

    can you post a live link to a page with that template?

    alternative structure (no fixed open and close divs, all done by conditional statements using the lop counter current_post)

    <?php $custom_query = new WP_Query( $args );
    while($custom_query->have_posts()) : $custom_query->the_post();
    				   if($custom_query->current_post % 6 == 0) { echo "\n".'<div class="row"><div class="movie_list">'; } //open divs ?>
    				 <div class="col-md-2">
    					<div class="well">
    						OUTPUT
    					</div>
    				 </div>
    				 <?php if($custom_query->current_post % 6 == 5 || $custom_query->current_post == $custom_query->post_count-1 ) { echo "\n".'</div></div>'; } //closing divs
    endwhile;
    wp_reset_postdata(); // reset the query ?>
    Thread Starter modeman

    (@modeman)

    Here is the full file code:
    https://pastebin.com/SdA58VRV

    Here is the live demo of this code:
    https://test.filmas24.lt/top-filmai/

    With your’s code i get this error:
    Parse error: syntax error, unexpected $end in /home/patiekal/domains/filmas24.lt/public_html/test/wp-content/themes/filmai_theme/page-templates/page-top-movies.php on line 1

    to eliminate any pph problems, try to change this section:

    <?php
    
      //Set the counter to 1
      $i = 1;
    
      //Open the row div
      echo '<div class="row"><div class="movie_list">'; ?>

    to:

    <?php
    
      //Set the counter to 1
      $i = 1; ?>
    
    <div class="row"><div class="movie_list">

    With your’s code i get this error:

    the code is not tested and is not meant for copy/paste – just as an illustration of the use of ‘current_post’ to output the divs.

    Thread Starter modeman

    (@modeman)

    Worked, big thanks to you ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WP_Query items count’ is closed to new replies.