Forums

[resolved] I need to "spoof" the name of the month (8 posts)

  1. mconn
    Member
    Posted 1 month ago #

    I'm not certain if this can even be done, and after searching for a couple of days, I just need to ask the question and see if anyone has an idea how I can make this happen.

    Here is the scenario: I have developed a WP site for a monthly magazine. They want the articles published online when the paper version is arriving in mailboxes, but it's a month ahead. In other words, people receive the October issue in September, the November issue in October, etc. Now when the articles get published online, the drop-down menu shows "October" but the articles are really from the November issue. Is there a way to "spoof" what the drop-down menu shows, so people could select "November" but would really be pulling articles that went live in October?

    I'm not a coder, but am comfortable making modifications when and where necessary.

    Any help would be great!

    MC

  2. t31os_
    Member
    Posted 1 month ago #

    And how do you view the monthly archives? Just by clicking a regular WordPress style month link?

    Examples:

    somesite.com/?m=08
    somesite.com/08/
    somesite.com/2009/08

    You could apply a filter to month requests so they are offset by a month, that way when you get a request for say..

    somesite.com/08

    it would in fact be grabbing data for..

    somesite.com/09

    Is that what you want to do?

  3. mconn
    Member
    Posted 1 month ago #

    Kind of. Currently using the archive widget, so it's a drop-down menu in a sidebar. When you select "August" I need for it to get the August articles, which would in actuality have been posted in July...

  4. t31os_
    Member
    Posted 1 month ago #

    Ok, so you want it to back date to the previous month.

    Could use a filter for archive pages, assuming thats where you want to do the back dating...

    // The magic!..
    if( !function_exists('backdate_archive') ) {
    	function backdate_archive($query) {
    		// If it's an archive query and it's not the admin area
    		if( !$query->is_admin && $query->is_archive ) {
    			// Make sure the month is set in the request
    			if( $query->get('monthnum' )) {
    				// Set the month to the new value
    				$query->set(
    					'monthnum',
    					$query->get('monthnum') - 1 // Back date
    				);
    			}
    		}
    		// Return the query (with new values if conditions were met).
    		return $query;
    	}
    	// Add filter before the query is run, ie. before getting the posts
    	add_filter('pre_get_posts', 'backdate_archive');
    }

    Modify as required.. :)

  5. mconn
    Member
    Posted 1 month ago #

    I've been out of the country for a couple of days, and am just getting back into the office.

    Thanks for the code... I'll try, tweak, and report back either way.

  6. mconn
    Member
    Posted 1 month ago #

    Hmm. I took the code and pasted into the functions.php (actually, custom_functions.php, I am using the Thesis theme, so placed this into the custom_functions.php using the thesis_hook_archive_template hook) but it doesn't modify anything at all. No change in behavior. So I'm wondering if I added it into the right place....

  7. t31os_
    Member
    Posted 1 month ago #

    So if you view a monthly archive there's no difference?

    Example url:
    yoursite.com/?m=09

    The code above was tested directly in my theme's functions file as working.

  8. mconn
    Member
    Posted 1 month ago #

    Nope. Doesn't work for some reason. But thanks to "girlie" over at diythemes (she's a pure genius), I am going to be creating categories for each month - January category, February category, etc, - and then simply using the category widget. Pure-d-simplicity and much easier too!

    Thanks for you help though dude!

Reply

You must log in to post.

About this Topic