[theme-reviewers] Pagination Question

Philip Walton philip at philipwalton.com
Fri Apr 22 21:30:43 UTC 2011


Sorry if my post came across as spamming the list for tech support. I 
thought the dilemma might be a common issue for theme developers.

In any case, a custom query filter ended up being an easy solution, so 
if anyone else has this same issue, here's how I solved it:

function tef_pagination( $limit )

{

     if ( is_home() ) {

         $paged = get_query_var('paged') ? get_query_var('paged') : 1;

         $post_per_page = $posts_per_page = get_option('posts_per_page');

         

         // make $posts_on_homepage an odd number

         $posts_on_homepage = ($posts_per_page % 2) ? $posts_per_page : $posts_per_page - 1;

                 

         if ( 1 == $paged ) {

             $limit = "LIMIT 0, $posts_on_homepage";

         }

         

         if ( 2<= $paged ) {

             $limit = "LIMIT " . ( ($paged - 2) * $posts_per_page + $posts_on_homepage ) . ", $posts_per_page";

         }

     }

     return $limit;

}

add_filter( 'post_limits', 'tef_pagination' );




On 4/22/11 1:49 PM, Chip Bennett wrote:
> This one might be a bit off-topic for the Theme-Reviewers mail-list...
>
> You might try the wp-hackers mail-list for this kind of question, or,
> perhaps better yet, wordpress.stackexchange.com
>
> Hope you find a solution. Sounds like a tricky problem!
>
> Chip
>
> On Fri, Apr 22, 2011 at 3:34 PM, Philip Walton<philip at philipwalton.com>wrote:
>
>> I'm making a theme for a client, and I'm coming up with an interesting
>> issues that I thought I'd run by you all before I do anything too hackish.
>>
>> Basically I'm making a theme where, according to the design, the home page
>> should display 9 posts, but every other page should display 10. The 10 page
>> design shows only the excerpts and looks like stacked blocks: 2 columns,
>> five high (all excerpts are equal height and width). The reason there's only
>> 9 posts on the home page is because the first post shows the entire content,
>> and then there's the stacked blocks below that first post. Basically, in
>> order to make it symmetrical, there needs to be an odd number of posts
>> displayed on the first page, but an even number on every other page.
>>
>> So here's my question:
>>
>> If I say posts_per_page = 9 on the home page, but 10 on every other page,
>> the pagination messes up. When I go to page 2 I either skip a post or show a
>> post that was also shown on the home page.
>>
>> Can anyone think of a way to make page 1 be 1-9 and the subsequent pages
>> 10-19, 20-29, 30-39, etc?
>>
>> I've come up with nothing so far and I'd rather not have to manually filter
>> the limit in the MySQL query.
>>
>>
>> _______________________________________________
>> theme-reviewers mailing list
>> theme-reviewers at lists.wordpress.org
>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>
>
>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110422/2cb098f0/attachment.htm>


More information about the theme-reviewers mailing list