Support » Developing with WordPress » Avoid showing same text in multiple loops

  • Resolved taghaboy

    (@taghaboy)


    Hi,
    I use this multiple loops to show the sold of some wears, so if there are the sold (meta_value=yes) the txt or presentation must be showing one time in top, and others products in bottom, and if the (meta_value=non) the users see a msg like : No sold available.

    in this loop the only problem is the presentation, it showing many time in the top, so pls how can i let it to be showing one time?

    Thanks

    <?php query_posts('post_type=wear&meta_key=sold&meta_value=yes'); ?>	
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<p>I'd like this presentation to be showing one time if there is the sold</p>
    <?php endwhile; ?>
    
    <?php rewind_posts(); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    	<h1>Yes, there is some sold</h1>
    <?php endwhile; ?>
    
    <?php else : ?>
    	<h1>No sold available</h1>
    <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,
    The Sold” is the promotion of the price of certain clothes.
    My goal is to have a loop who will search in the clothes store (post_type=wear), if there are a promotion (meta_key=sold), if yes (meta_value=yes) the loop will first show a presentation just one time, and then to post all the articles of Promotion/Sold clothes.
    else, if there is no Sold (meta_value=no), the phrase will be No sold available
    This is what i wanna do with that Loop.
    Thanks

    • This reply was modified 2 weeks, 2 days ago by  taghaboy.

    If you want to show a message if have posts, maybe you can change the code to be like this:

    
    <?php query_posts('post_type=wear&meta_key=sold&meta_value=yes'); ?>
    <?php if (have_posts()): ?>
    	<p>I'd like this presentation to be showing one time if there is the sold</p>
    <?php endif; ?>
    
    <?php while (have_posts()) : the_post(); ?>
    	<h1>Yes, there is some sold</h1>
    <?php endwhile; ?>
    
    <?php else : ?>
    	<h1>No sold available</h1>
    <?php endif; ?>
    
    

    Thanks @lai32290 for your help,
    Unfortunately ur code generate error !

    I’m so sorry, you’re right, there’s a bit of issue in the code, please try this one:

    
    <?php query_posts('post_type=wear&meta_key=sold&meta_value=yes'); ?>
    <?php if (have_posts()): ?>
    	<p>I'd like this presentation to be showing one time if there is the sold</p>
    
    <?php while (have_posts()) : the_post(); ?>
    	<h1>Yes, there is some sold</h1>
    <?php endwhile; ?>
    
    <?php else : ?>
    	<h1>No sold available</h1>
    <?php endif; ?>

    Hello @lai32290 🙂 Great work, it work as i want it ! awesome
    My last question, is there any problem using query_posts ? someone say to never use it and should be avoided !!!
    Thanks a lot.

    • This reply was modified 2 weeks, 1 day ago by  taghaboy.
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.