Display post after the last 6

Asked

Viewed 35 times

1

Hello, I have a question in the condition of the constructor of the Wp_query() wordpress class

At the top of the blog I have a loop showing in a slider jquery the last 6 blog posts

  $query1 = new WP_Query( "showposts=6" );
  while ( $query1->have_posts()) : $query1->the_post();

so far correct, but in the body of the blog I would like to display only the posts that came before, ie.. the last 6 in the slider and the others in the blog listing the posts

The problem is that if I put the ascending order it takes the old posts first in the body of the blog

$query2 = new WP_Query( "order=ASC&showposts=+6" );
while ( $query2->have_posts()) : $query1->the_post();

The posts with the ID’s are from the following manteira in the slider: ID 10 - ID 9 - ID 8 - ID 7 - ID 6 - ID 5 - ID 4

And on the blog: ID: 1 ID: 2 ID: 3

Understand each ID as a post

2 answers

0

If you don’t need to worry about paging, offset resolves:

$query2 = new WP_Query( "showposts=6&offset=6" );
while ( $query2->have_posts()) : $query1->the_post();

offset=6 makes the query skip the first 6 posts and catch the next six.

--

If you need paging at the bottom, you can take the Ids from the first query and delete from the following:

$query1 = new WP_Query( "showposts=6" );
$query1_IDs = wp_list_pluck( $query1->posts, 'ID' );
$query2 = new WP_Query( array( 'showposts' => 6, 'post__not_in' => $query1_IDs ) );

-1

You can make a counter and only print from the 6

while(suas condições){
for(i=0;i>=6;i++){ seu echo }
}

see if this helps you ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.