Paginated search results

Posted by on May 10, 2012 in Blog, Mylo, Storefront Themes, WP e-Commerce | No Comments

The problem

Search results only return as many as set in WordPress Settings/Reading “Blog pages show at most X posts”

Solutions

You could raise that number but in a e-Commerce situation that could be impractical if you also run a blog. The solution is to add pagination to the search results.
Check out this link http://design.sparklette.net/teaches/how-to-add-wordpress-pagination-without-a-plugin/
I think it is a very nice solution for what you want, and it looks good in the theme as is.

STEP 1
To avoid issues implementing this I suggest a couple of changes. In the code to add to functions.php change the class name to avoid any clash with WP e-Commerce pagination
For example `class=\”pagination-search\`
STEP 2
Then change all the .pagination in the CSS to .pagination-search
STEP 3
Not a change just the location
The last 3 lines of search.php in the Mylo folder should be

</div>

</div><!-- end Container 12 -->

<?php get_footer(); ?>

Put the code from step 3 right above those 3 lines

*********************

That will get you pagination. It will be one post per page as your blog is set. To return a certain number of results per page ignoring the reading setting you need to add this line of code in 2 places in search.php
This is the line, change the number to what you want

query_posts("$query_string . '&posts_per_page=2'");

Put it after this line, which is around 26

query_posts($query_string . "&post_type=wpsc-product" );

and after this line which is around line 81

query_posts($query_string . "&post_type=post");

Just to be clear you will end up with something that looks like this each time except for post_type=post or wpsc-product

<?php
		global $query_string; // grab the search query
                query_posts($query_string . "&post_type=post");
		query_posts("$query_string . '&posts_per_page=2'");
		?>
		<?php if (have_posts()) : ?>

Leave a Reply