Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [WordPress] Multiple loops & pagination (Sticky posts not on absolute top) Re: [WordPress] Multiple loops & pagination (Sticky posts not on absolute top)

#106952
Spiekerboks
Participant

Hi all,

Since the post above I’ve made some progress but I’m not really there yet, some help would still be greatly appreciated ;).

Using three separate loops and an offset I managed to get close to the desired effect. Sadly pagination does not work anymore since the template file now requests a specific and static number of posts. An example applied on my author-page: http://www.wattisduurzaam.nl/author/admin/ shows exactly the same posts as
http://www.wattisduurzaam.nl/author/admin/page/6/

My code looks something like this:


// Requests latest normal post, excluding the announcement category
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

//... content for loop 1...//

endwhile; endif;// End the Loop and Check for Posts
wp_reset_query(); // Reset the loop
?>

// Requests latest post in announcement category
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

//... content for loop 2...//

endwhile; endif;// End the Loop and Check for Posts
wp_reset_query(); // Reset the loop
?>

// Requests latest eight normal post, excluding the announcement category and without duplicating the first entry
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

//... content for loop 3...//

endwhile; endif;// End the Loop and Check for Posts
wp_reset_query(); // Reset the loop
?>

Searching for a solution I stumbled upon this snipped quite often:

'paged' => get_query_var('paged')

This indeed does work for one loop but I do not yet see how to translate this to work for all three off them without duplicating posts.

Does someone maybe know of a method to use the pagination as a multiplier in the post query and for the offset?

It is good enough if the announcement is displayed only on the homepage, another idea therefore was to let the pagination on home.php (with the above three loops) redirect to index.php (with just the standard loop). Unfortunately I did not find a way to prevent home.php from overruling index.php on deeper pages. An attempt to put all the custom loops within an is_home block and the normal loop in an else block did not workout either (probably due to nested if loops which have to remain in place for other functions).

So, does anyone know of a method to restore the pagination with these custom loops?

Thanks in advance!