WordPress.org

Ready to get started?Download WordPress

Forums

Multiple loop, querying some categories (2 posts)

  1. carlodurso
    Member
    Posted 1 year ago #

    I'm trying to generate posts from a given category creating 2 nested loops, therefore the main loop will be mixed up with some specific category posts. I've tried to hack the code Displaying ads after every third post without much luck so far.

    The trouble is that I have no control on the posts shown on the page. For instance, given the code below I get the same posts on a given page and most of the times on several pages.

    My goal is to loop through all the available posts in the category and show each of them twice on each page. When there are no more posts just not to show anything.

    This is the code I'm working on:

    $custom_query = new WP_Query('cat=176&posts_per_page=1&orderby=rand');
    
    while (have_posts()) : $ad_counter++; the_post();
    
    $ad_counter = $ad_counter % $after_every;
    
    while ($custom_query->have_posts()) : $custom_query->the_post();
    
                if(( 0 == $ad_counter)) {
    		//$do_not_duplicate[] = $post->ID;
    		//print_r($do_not_duplicate); ?>
    
    	  <article>//Looping</article>
    
          <?php }
          endwhile;
            wp_reset_query();

    Any help in the right direction will be greatly appreciated.

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Try:

    $custom_query = new WP_Query('cat=176&posts_per_page=1&orderby=rand');
    while ( $custom_query->have_posts() ) : $custom_query->the_post();

Topic Closed

This topic has been closed to new replies.

About this Topic