you could use the ‘offset’ parameter with query_posts():
http://codex.ww.wp.xz.cn/Function_Reference/query_posts#Offset_Parameter
disadvantage: is you want to use paginatin at a later point, it won’t work together with ‘offset’.
or you could get the post from the first loop and use one of the mothods to avoid duplicate posts;
described in here:
http://codex.ww.wp.xz.cn/The_Loop#Multiple_Loops_in_Action
Thanks for the reply.
This is how my code looks like now:
<?php $my_query = new WP_Query('category_name=Noticias&posts_per_page=3');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate[] = $post->ID?>
<h3 id="post-<?php the_ID(); ?>">
<?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
if (in_array($post->ID, $do_not_duplicate)) continue;?>
<h3 id="post-<?php the_ID(); ?>">
<?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
Sorry for my ignorance, but I still have the same problem.
The 3 latest posts are showed, but the last one is the one I don’t want to show, I suppose is the one which is not going to be duplicated, but it still shows.
The thing is, how can I make reference to the last post and tell it not to show up? Because I’m already showing it above with this code:
<div id="noticia_info">
<h2 id="post-<?php the_ID(); ?>">
<?php the_title(); ?></h2>
<p><a href="<?php the_permalink() ?>">Ver artículo</a></p>
</div>
I don’t know if I’m making myself understood, my English isn’t that good 🙁
try to add the line $do_not_duplicate[] = $post->ID;
into here:
<div id="noticia_info">
<h2 id="post-<?php the_ID(); ?>">
<?php the_title(); ?></h2>
<p><a href="<?php the_permalink() ?>">Ver artículo</a></p>
</div>
maybe in this way:
<div id="noticia_info">
<?php $do_not_duplicate[] = $post->ID; ?>
<h2 id="post-<?php the_ID(); ?>">
<?php the_title(); ?></h2>
<p><a href="<?php the_permalink() ?>">Ver artículo</a></p>
</div>
and then, for your ‘other news’ section, try to use this code:
<?php
query_posts(array ('posts_per_page' => 3, 'post__not_in' => $do_not_duplicate) );
if (have_posts()) :
while (have_posts()) : the_post();?>
<h3 id="post-<?php the_ID(); ?>">
<?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php else : ?>
<h3 class="center">No se han encontrado entradas</h3>
<p class="center"><?php _e("Lo siento, pero lo que estas buscando no esta aqui."); ?></p>
<?php endif;
//Reset Query
wp_reset_query();
?>
It worked!
Thank you so much.
you are welcome.
well done,
multiple loops can be intimidating at times – but you mastered them 😉
(you could tick this thread off as ‘resolved’ – there is a checkbox or dropdown somewhere)