• hi, my current blog is at movable type:
    https://www.stefoodie.net

    but i’m preparing to switch over to wordpress — i’ve got the site working here:
    https://www.stefoodie.net/wpblog/

    what i’d like to do is put 4 links in the right column that will correspond to the 4 seasons, such that, e.g., all posts from september 21 (in all years) to december 20 (in all years) will be displayed when someone clicks on the “fall” link, all posts from dec 21 – march 20 will be displayed when “winter” is clicked, etc. i’m a beginner coder, and i don’t mind learning to code on my own, but would love to get some advice on where to start. i found a post with if-then statements (?) here on this forum, and it looks like i could use it, but i’m still not sure exactly how. TIA for any advice.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I guess nobody helped you on that one, huh? I too am working on a similar thing, and I was hoping someone might have implemented something. I’m building a site for a magazine and basically, if I could implement a kind of intermediate archive type — a seasonal or quarterly archive category, ie. organizing everything by season — then I wouldn’t have to make the archives so nasty. As it is, I was imagining creating a new category for each season/year, and then creating a new subcategory in each new season for the excerpts in that issue of the quarterly.

    I’m quite sure there are two or three ways to do it, but I had just hoped that if someone had already worked it out, I could nab their code. Ah well…

    oooh, ooh, looks like an answer might be here, at least for me!
    https://www.ads-software.com/support/topic/33751

    You can write your own SELECT command within The Loop so MySQL groups published posts by quarter. What you then do with the posts and postdata is a personal PHP programming exercise.

    Here’s the PHP query:
    $sql = ‘SELECT *, YEAR(post_date )+(CEILING(MONTH(post_date )/3 )/10 )AS \’Qtr\’ FROM wp_posts WHERE post_date <now() AND post_status =\’publish\’ ORDER BY Qtr ASC’;

    It creates a temporary table called Qtr which only exists for the duration of this query and is not a part of the database per se. The column Qtr holds a number crafted from the year, such as 2002, and a decimal portion .10, .20, .30, or .40 corresponding to calendar quarters.

    Qtr is an ordered list along the lines of 2002.10, 2002.20, 2002.30, 2002.40 folowed by 2003, 2004, 2005 and so on. MySQL has done most of the heavy work for the programmer.

    The primary engine component is CEILING(MONTH(post_date )/3 ). It would take an offset value to change the SELECT rule from calendar quarters to seasons or to match college quarters. I haven’t worked with that yet but it looks like a simple conditional would work and thats easiest in PHP.

    More along the same lines:

    To implement a quartely magazine, I decided to use the categories as seasons and years — thus I can use all the features of WordPress categories. I’m using category titles like Summer 2002, Spring 2003, and so on.

    In home.php I calculate the current quarter and craft that into a category name so I can show posts restricted to the current season. All the other posts are archived by their seasonal names.

    Seasonal quarters do not match calendar quarters. Think of fiscal years, which might begin and end on any month. An offset factor is needed to force non-calendar years into four quarters. The basic formula follows in PHP speak.

    $last_month_of_the_year = 11;
    The end month of your year. Here I’ve used November, the last month of Fall, because I start my new years with Winter — Dec, Jan, and Feb as Q1. You could say your last month is 2 — February — if you wanted to start your new year on March 1st.

    $factor = ( 21 – $last_month_of_the_year );
    The number here is the offset value. This is from a standard formulary and, since I am not at all mathematically inclined, I simply looked up a formula that calculates the fiscal quarter any given date falls in.

    $currentQuarter = ceil((date(‘n’) + $factor) /3) %4 +1 ;
    Current month plus factor are divided by 3, rounded up by CEIL, and the special PHP devisor %4 takes only the remainer of division by 4 and drops the rest of the answer. Add 1 to that remainder and you will have the correct current quarter 1 through 4 for the defined fiscal year.

    Generally, fiscal years start and end whenever the accountant says they do. I defined my year to match the seasons: Q1 is Winter, Q2 is Spring (March, April, May), Q3 is Summer (June, July, August), and Q4 is Fall (September, October, November). That definition took place on the first line when I set $last_month_of_the_year.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Link to Seasonal Posts?’ is closed to new replies.