I need to make adjustments to a horribly written WP theme that (a custom theme that was written in tables, and bad code).
The theme has several custom templates, but pagination wasn’t used and get_posts was used in place of query_posts –
<?php query_posts('showposts=1'); ?>
<?php $posts = get_posts('numberposts=10&offset=0&category_name=albertsons, carrs, dominicks, genuardis, heb, kroger, pavillions, publix, randalls,safeway,shop-rite,tom-thumb,vons,whole-foods'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count2 = 0; if ($count2 == "10") { break; } else { ?>
...
<?php $count2++; } ?>
<?php endforeach; ?>
I need to get pagination to work with get_posts, or rewrite the function to use query_posts only, so that I can add 'paged' => get_query_var('page')
When I try to rewrite to only use query_posts, the whole damn thing breaks.
Any thoughts on how to improve?
Thanks
UPDATE:
<?php
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array('posts_per_page' => '3','paged'=>$paged,'category_name'=>'albertsons, carrs, dominicks, genuardis, heb, kroger, pavillions, publix, randalls,safeway,shop-rite,tom-thumb,vons,whole-foods')); ?>
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
Which works, but is not paginating. “Older posts” will reload the page with the url page-2, but the content is exactly the same – meaning the exact same posts are showing as on first page.
Solved – needed to use
You can replace the code with something like this
then call normal Post Loop like
Btw, I will advice going against query_posts/get_posts and use WP_Query
Hope that helps to get you started 🙂