• I have three loops om my index page in order to list last 5 posts according to GD Star Rating popularity in each of them. The listings are just title and a custom field related image. They are supposed to appear in 3 distinct columns, post 0-5,post 6-10, post 11-15.
    instead I get one huge one-column list looping in the endless and no break in the next column. And it is only the latest posts image used for all posts listed…Any skilled eye spotting anything strange in the first loop as presented below?:

    <div id="column_01">
    <?php query_posts('gdsr_sort=review&sort_order=asc&gdsr_multi=1&showposts=5&cat=3,5,6,9,31'); ?>
    
    <?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>
    <?php
    if($post_image !== '') {
    ?>
    <h2><a href="<?php the_permalink() ?>"  rel="bookmark" title="Permanent url to <?php the_title(); ?>"><?php the_title(); ?><br />
    <img src="<?php echo $post_image; ?>" alt="<?php if($post_alt !== '') echo $post_alt; else the_title(); ?>" style="width:250px;height:190px " /></a></h2>
    <?php }
    else {
    echo 'missing image';
    } // endelse
    ?>
    
    <?php $count1++; } ?>
    <?php endforeach; ?>
    </div>

Viewing 4 replies - 1 through 4 (of 4 total)
  • 1. this line:

    <?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>

    in the foreach loop, you are setting the $count1 variable to 0 (zero) and immedeately after checking if it equals 5 – which can never be => endless loop.

    you could better move the initiation of the counter to before the ‘foreach’:

    <?php $posts = get_posts('numberposts=5&offset=0'); static $count1 = 0; foreach ($posts as $post) : start_wp(); ?>
    <?php  if ($count1 == "5") { break; } else { ?>

    2.
    where is $post_image defined?
    shouldn’t be there some $post_image = get_post_meta(......); ??

    Thread Starter ThorHammer

    (@thorhammer)

    alchymyth: Thank you for your reply!! Aha, so it really IS an issue with the custom loop… I will try your solution!

    2: Sorry, I defined the variable ABOVE the custom query, the variable is equal to a post-related image, stored as a custom field value.

    I look forward to try your suggestion when I get back from work!!

    @thorhammer:

    I defined the variable ABOVE the custom query, the variable is equal to a post-related image,

    imho, in this case you will show the same image five times (?)

    as far as i understood, you want to show five different post related images in your loop (?)

    Thread Starter ThorHammer

    (@thorhammer)

    alchymyth: eh.. *blush*… So that’s why… I thought I could interfere with the query if I put the variable definition within the loop.
    Thank you. Again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple loop problem…’ is closed to new replies.