Today I had a real problem with a WordPress website that uses multiple wp_query calls on the home page. The issue was that I could not use the next_posts_link() function properly, since WordPress ignores the “offset” parameter when creating paginated pages.
The solution I used was found here on the WordPress Codex.
Here is the code:
1) ? ($onum) : 0; query_posts("posts_per_page=$qry[total]&paged=$paged&showposts=$qry&offset=$offset"); if (have_posts()) : while (have_posts()) : the_post(); // Loop stuff endwhile; endif; // Reuse the offset variable (rather then creating a new one), setting to a new value (plus any additional offset) // Total in first query, plus any offset, if there is one $offset = $qry + (($paged > 1) ? $onum : 0); query_posts("posts_per_page=$qry[total]&offset=$offset&showposts=$qry"); if (have_posts()) : while (have_posts()) : the_post(); // Loop stuff endwhile; endif; // Again just reusing the variable and adding offset (if page is more then 1) // First posts total, plus second posts total, plus offset (if there is one).. $offset = ($qry + $qry) + (($paged > 1) ? $onum : 0); query_posts("posts_per_page=$qry[total]&offset=$offset&showposts=$qry"); if (have_posts()) : while (have_posts()) : the_post(); // Loop stuff endwhile; endif; // Unset the variables (we've finished with them, no reason to hold onto them) unset($qry,$offset,$onum); ?>
Can you think of an easier way to do this?
More posts from themightymo.com
GoDaddy owns ManageWP, and, strangely, they make it very difficult to add GoDaddy-managed WordPress sites to their ManageWP service. Thankfully, there’s a quick workaround: Visit https://yoursite.com/wp-admin/plugins.php?showWorker=1 — This will make the ManageWP “Worker” plugin visible. Copy the connection info from the ManageWP Worker plugin. Add the site per-normal on ManageWP. That’s it! I hope this…
I realized this morning that my TMM Maintenance Mode WordPress plugin had a bug that was causing the wp-login.php page to be inaccessible. The solution was to write a simple function that checks whether or not we’re currently on a login page, and then add a call to that function in my code. Here’s the…
Today I updated a WooCommerce site, and everything worked fine, except for the images on product pages – they were not displaying at all. After a lot of trial & error, I realized that WP Rocket was to blame. I’m not sure exactly what the issue was (though my hunch is that it had to…