Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I found a script so I can take care that on some months I can change the number of post at a page.

So I implment this script at this way : http://pastebin.com/Nbqy0KBU

But still all articles are displayed as you can see here : http://test.tamarawobben.nl/2005/04

Anyone a idea why and how to solve this ?

Roelof

Edit 1 :

What I want to achieve is this in pseudo code.

When the year is 2005 and the month april(04) and we are on the first page of that month then 1 article must be displayed. if not then the standard number of articles must be displayed.

share|improve this question
1  
Can you explain what's the significance of the year and month in this? The 'page' I can understand, but year and month? How flexible are you looking for this solution to be? –  soulseekah Oct 21 '11 at 10:28

3 Answers 3

up vote 0 down vote accepted

Consider this option of achieving what you seem to be requiring:

function wpse31701_filter_query() {
    global $wp_query;
    // Check year and month
    if ( $wp_query->get( 'year' ) == 2005 and $wp_query->get( 'monthnum' ) == 5 )
        // Check page number to apply offset
        if ( $wp_query->get( 'paged') > 1 ) $wp_query->set( 'offset', 1 );
        else $wp_query->set( 'posts_per_page', 1);
}
add_action( 'pre_get_posts', 'wpse31701_filter_query' );

Here we alter the query as soon as $the_query is ready to get the posts, to modify the posts_per_page to 1 if paged is 1, and apply and offset of 1 post if paged is > 1.

The important thing is to apply offset and posts_per_page; the rest is purely conditional so apply to taste.

share|improve this answer
    
Oke, and to test this I have to put it into functions.php ? –  Roelof Wobbn Oct 21 '11 at 10:49
    
Theoretically - yes. –  soulseekah Oct 21 '11 at 10:55
    
I changed the action hook to pre_get_posts instead, it's a more suitable hook; things happen after parse_request... –  soulseekah Oct 21 '11 at 11:07
    
Oke, Can I also change the sort order so the oldest article get displayed first. –  Roelof Wobbn Oct 21 '11 at 11:49
    
Sorry, I see a problem now. the frontpage is now showing all the articles but not the frontpage message. Can the script causes this ? –  Roelof Wobbn Oct 21 '11 at 11:55

is_category(); is checking if you're on a category archive or not. So, is_category('1perpage'); will only return true when you're on http://test.tamarawobben.nl/category/1perpage/

share|improve this answer
    
+1 that's what I was typing... –  soulseekah Oct 21 '11 at 9:46
    
oke, Bad way to go. –  Roelof Wobbn Oct 21 '11 at 9:59
    
Find another way to achieve what I want. To put 1 articles on the first page of that month and the rest on the second page of that ,month –  Roelof Wobbn Oct 21 '11 at 10:01
    
You may be able to achieve the same thing using sticky posts - but I haven't worked with them enough to know all the ramifications of marking a post as sticky. –  Taylor Dewey Oct 21 '11 at 10:05
    
Could I use if_year=2005 and if_month=04 and if_paged() ?? –  Roelof Wobbn Oct 21 '11 at 10:06

It doesn't look like there are any template tags to achieve what you want, so you're stuck comparing the query string (try get_query_var(query_vars)) to 200504

From the $WP_Query object: ... [query_vars] => Array ( [m] => 201110 ...

If it's a match, you have a multitude of options... I might try an if/then bracket... psuedo code:

 if ($queryvar == '200504' && $paged == 1):
    $singlepost = get_post(...);
    // write display code for your singleton post.
 else:
    query_posts($query_string.'&offset=1');
    //run through the normal loop code here
 endif;

This is still likely to mess with paging, which is the sticky wicket here... I'm sure someone else can come up with a better answer, but maybe that'll get you started.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.