troubleshooting Question

for loop counter $i=1;$i<=3;$i++ in wordpress is creating duplicates

Avatar of niceoneishere
niceoneishere asked on
WordPressPHPWeb Development
2 Comments1 Solution950 ViewsLast Modified:
I am using the below php code to add a class to each post from a specific category. The counter adds the number to class but each of the is adding 3 times. here is my mark up
	 <ul class="ul">	 
	 <?php query_posts('showposts=3&cat=3&orderby=rand'); if (have_posts()) : while (have_posts()) : the_post(); ?>
	 <?php for ( $i=1; $i<=3; $i++ ) { ?>
	 <li class="li<?php echo $i ?>"><a href="<?php $postid = $wp_query->post->ID; echo get_post_meta($postid, '_wpb_nsl_text', true);  ?>" title="<?php the_title_attribute(); ?>"><?php print $post->post_title; ?></a>
	 <a href="<?php $postid = $wp_query->post->ID; echo get_post_meta($postid, '_wpb_nsl_text', true);  ?>"><?php the_post_thumbnail('blog-post-image'); ?></a>
	</li>
		<?php } ?>
	<?php endwhile; else : endif; ?>
	<?php wp_reset_query(); ?>
	</ul>
The result is like below and as you can see its creating 3 li's for each post instead of only one
<ul class="ul>
 <li class="li1">post 1 </li>
 <li class="li2">post 1 </li>
 <li class="li3">post 1 </li>
 <li class="li1">post 2 </li>
 <li class="li2">post 2 </li>
 <li class="li3">post 2 </li>
 <li class="li1">post 3 </li>
 <li class="li2">post 3 </li>
 <li class="li3">post 3 </li>
</ul>
What I am looking is
<ul class="ul>
 <li class="li1">post 1 </li>
 <li class="li2">post 2 </li>
 <li class="li3">post 3 </li>
</ul>
What am I missing?
Thanks
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros