Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Multiple loops on a page pulling content & images from post WordPress

  • REFUNDED

http://propono.co.uk/clients/curo/medical-reimbursement

This is the code thats powering the links at the bottom in the grey box:

Whatever I try I can't get it to pull out the images and the content.

I have categories called mlinks, llinks and links, and will need to do this on three different pages with each of those categories which represent a page.

So I'm trying to get:

image 1 post 1 | image 4 post 6
image 2 post 2 | image 5 post 6
image 3 post 3 | image 6 post 6


<div id="link-box">
<p id="linkbox-top">Medical Reimbursement Links</p>

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

<div class="linkgroup"><!-- FIRST LOOP: display posts 1 thru 3 -->
<div class="small-boxes">
<div id="img"><img src="<?php echo get_post_meta($post->ID, 'medical', true); ?>" alt="slide<?php the_ID(); ?>" width="84" height="55"/></div>
<div id="txt">
<h5 class="txt1"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h5>
<?php echo content(); ?>
</div>
</div>
</div>

<?php $count1++; } ?>
<?php endforeach; ?>

<?php query_posts('category_name=mlinks&showposts=3'); ?>
<?php $posts = get_posts('numberposts=3&offset=3'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count2 = 0; if ($count2 == "3") { break; } else { ?>

<div class="linkgroup"><!-- SECOND LOOP: display posts 1 thru 3 -->
<div class="small-boxes">
<div id="img"><img src="<?php echo get_post_meta($post->ID, 'medical', true); ?>" alt="slide<?php the_ID(); ?>" width="84" height="55"/></div>
<div id="txt">
<h5 class="txt1"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h5>
<?php echo content(30); ?>
</div>
</div>
</div>

<?php $count2++; } ?>
<?php endforeach; ?>

</div>


Can any one help please.

Thankyou

Answers (1)

2010-04-10

Buzu B answers:

Hi.

<strong>*EDIT:*</strong>
I think the loop is just part of the problem. I see the las item displays correctly, so there must be a problem with the post meta data of the other posts. Apparently, get_post_meta() is returning nothing because nothing is printed by the echo statement. You sould check your database and see if there is any meta data for the posts that don't show any in the loop. I guess, since you loop seems to be working fine, you can leave it like it is.



-----Original message:

One thing I noticed is that you are using quotes ("") around your 3 in the fifth line:

<?php static $count1 = 0; if ($count1 == "3") { break; } else { ?>

Now, that is not the cause of the problem, but you shouldn't use quotes when comparing numbers. It should be like this:

<?php static $count1 = 0; if ($count1 == 3) { break; } else { ?>

The the loop you might want to try like this:


<div id="link-box">
<p id="linkbox-top">Medical Reimbursement Links</p>
<?php query_posts('category_name=mlinks&showposts=3'); ?>
<?php $count1 = 0; ?>
<?php if(have_posts()) : while(heve_posts()) : the_post(); ?>
<?php if ($count1 == 3) { break; } else { ?>
<div class="linkgroup"><!-- FIRST LOOP: display posts 1 thru 3 -->
<div class="small-boxes">
<div id="img"><img src="<?php echo get_post_meta($post->ID, 'medical', true); ?>" alt="slide<?php the_ID(); ?>" width="84" height="55"/></div>
<div id="txt">
<h5 class="txt1"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h5>
<?php echo content(); ?>
</div>
</div>
</div>
<?php $count1++; } ?>
<?php endwhile; endif; ?>

<?php wp_reset_query(); ?>
<?php query_posts('category_name=mlinks&showposts=3'); ?>
<?php $count2 = 0; ?>
<?php if(have_posts()): while(have_posts()): the_post(); ?>
<?php if ($count2 == 3) { break; } else { ?>
<div class="linkgroup"><!-- SECOND LOOP: display posts 1 thru 3 -->
<div class="small-boxes">
<div id="img"><img src="<?php echo get_post_meta($post->ID, 'medical', true); ?>" alt="slide<?php the_ID(); ?>" width="84" height="55"/></div>
<div id="txt">
<h5 class="txt1"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h5>
<?php echo content(30); ?>
</div>
</div>
</div>
<?php $count2++; } ?>
<?php endwhile; endif; ?>
</div>



solidariti comments:

Hi Buzu B,

I took out the quotes for the numbers thank you but as you predicted this did nothing.

The loop that you gave me did not display any of the content at all. I was doing some work on this last night and I have it to display one of the images but the other images aren't being displayed? Whats wrong?

I'm also echoing <?php echo get_the_ID(); ?> which is being displayed on the page.