Jump to content

Mysterious While Loop


Grandioso

Recommended Posts

This is a wordpress website, but I'm not sure if it's a WP error or not (I think not), so I'm posting here.

 

Basically, I am listing a couple of entries into a list element for a JS slideshow.

There's a max_count variable set, which is used to break pages (close current and open new <li>) when post_counter reaches the same value.

 

The problem is, when the max_count is bigger than the total amount of elements, the loop does not output anything. It just doesn't make any sense to me and drives me crazy.

 

If anyone could solve this mystery, it'd be much appreciated. Here's the code.

 

<div id='home-slider-navig-left'>
<img alt='arrow_left' src='<?php echo get_template_directory_uri() ?>/design/img/navig_arrow_left.png' id='navig_arrow_left' />
</div>

<ul id='clients_home_ul' style="margin-top:20px;">

<?php

global $a_query_args;
global $b_show_client_link;

$o_clients_query = new WP_Query( $a_query_args );
$i_post_counter = 0;
$i_max_count = 6; //get_option( 'home_clients_postcount', 6 );
$i_page_counter = 1;

$b_new_page = true;

while ( $o_clients_query->have_posts() ) : $o_clients_query->the_post();

 // if new page, open new li element
 if ( $b_new_page )
 {
  $b_new_page = false;
  echo "<li class='clients_home_li page_{$i_page_counter}'>";
 }
 $i_post_counter++;

 // break content at 'show more' 
 global $more;
 $more = 0; 

 // BUILD CLIENT HEADING
 $s_permalink = get_permalink(get_the_id());
 $s_title = get_the_title();

 $s_client_heading = "<h3>";
 if ( $b_show_client_link )
  $s_client_heading .= "<a href='{$s_permalink}' title='{$s_title}'>{$s_title}</a>";
 else
  $s_client_heading .= $s_title;
 $s_client_heading .= "</h3>";

?>


<div class='clients_home_entry'>

 <div class='clients_home_entry_container'>

  <div class='clients_home_entry_image'>
   <?php the_post_thumbnail( 'clients_thumb' ); ?>
  </div>

  <div class='clients_home_entry_content'>
   <div class='relative'>
                   <?php echo $s_client_heading ?>
 <?php the_content( '' ); ?>
   </div>
  </div>

 </div>

</div>
<!-- eof clients_home_entry -->

<?php 
 // CLOSE LIST ITEM IF MAX COUNT IS REACHED
 if ( (($i_post_counter % $i_max_count) == 0) )
 {
  $i_page_counter++;
  echo "</li>";
  $b_new_page = true;
 }


endwhile;

//close last list item
echo "</li>";
?>

</ul>

<div id='home-slider-navig-right'>
<img alt='arrow_right' src='<?php echo get_template_directory_uri() ?>/design/img/navig_arrow_right.png' id='navig_arrow_right' />
</div>

<div class='space'></div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.