• In order to change my blog index into a multicolumn page, I went to a WordPress Codex (http://codex.wordpress.org/The_Loop#Multiple_Loops). The solutions did not work for me. Although I do not know anything about PHP, I made changes in the code until I found this solution that seemed to work:

    <div id="col1">
    	<?php if (have_posts()) : ?>
    	<?php $my_query = new WP_Query('category_name=Sociedad&showposts=10');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID;?>
    	<!-- do stuff ... -->
    	<?php endwhile; ?>
    </div>
    
    <div id="col2">
    	<?php query_posts('cat=-2&showposts=9'); // exclude the first category ?>
    	<!-- do stuff ... -->
    	<?php endwhile; ?>
    
    <div class="navigation"><strong>
    	<div class="alignleft"><?php next_posts_link('&laquo; ART&Iacute;CULOS ANTERIORES') ?></div>
    	<div class="alignright"><?php previous_posts_link('ART&iacute;CULOS POSTERIORES &raquo;') ?></strong></div>
             </div>
    </div>
    <?php else : ?>

    Nevertheless, I realized that navigation did not work. It always show the same post of index although the direction of navigator were the page 2 or previous. And I do not know how to fix it.

    Then I returned to try it with another solution of the Codex (that only worked when I changed to the last call <? php endwhile; endif; > into <? php endwhile; >. This is the new code:

    <div id="col1">
    	<?php $my_query = new WP_Query('category_name=Sociedad&showposts=1');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID; ?>
    	<!-- do stuff ... -->
    	<?php endwhile; ?>
    </div>
    
    <div id="col2">
    	<?php if (have_posts()) : while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    	<!-- do stuff ... -->
    	<?php endwhile; ?>
    
    <div class="navigation"><strong>
    	<div class="alignleft"><?php next_posts_link('&laquo; ART&Iacute;CULOS ANTERIORES') ?></div>
    	<div class="alignright"><?php previous_posts_link('ART&iacute;CULOS POSTERIORES &raquo;') ?></strong></div>
    	</div>
    </div>
    
    <?php else : ?>

    Navigation worked correctly, but I have realized it does not work as the Codex said (“The catch is that post should not to appear in both categories”). With this solution posts of the category Sociedad appear duplicate in both columns. And I do not know how to fixe it either.

    Thanks in advance to whoever can help me to fix one code or the other.

  • The topic ‘Problem with multiple loops’ is closed to new replies.