ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Calendar next/previous year link - Is it possible?

October 12, 2010 6:31am

Subscribe [3]
  • #1 / Oct 12, 2010 6:31am

    FirthCreative

    89 posts

    I am looking to use the native calendar functionality to provide a simple availability calendar on a project we are working on for a client. We have a channel setup to handle the booking dates and all is working fairly well. The client has requested that the calendar also have links to skip a year at a time in addition to the default month at a time links. I have scratched my head on this for a while trying to work out how to achieve it?

    Has anyone else managed to modify the links in this way? I was thinking it might require some sort of offset value or similar, but if I’m honest I can’t think how to implement it! I am 99% sure it will be possible, but I could use some assistance in getting it going…

    Any takers…

    Moved to CodeShare Corner by Moderator

  • #2 / Oct 12, 2010 4:10pm

    Ingmar

    29245 posts

    What version and build of EE are you using? Can you show us the relevant parts of your code? You might simply need to add to / subtract from your current year.

  • #3 / Oct 13, 2010 6:50am

    FirthCreative

    89 posts

    The site is currently sitting on 2.0.2pb, although we are updating it this week to 2.1. The code we have used for the calendar is basically is it is in the docs, no major changes other than anchor tags removed for cell data and a bit of CSS work.

  • #4 / Oct 13, 2010 3:15pm

    Ingmar

    29245 posts

    Upgrading to 2.1 is certainly a good idea. That said, I am not aware of a way to link to the next / previous year automatically. You’d need a bit of PHP for that, most likely.

  • #5 / Oct 14, 2010 10:39am

    FirthCreative

    89 posts

    I spent some time on this one today and cracked it!

    Thought I would slap my code in here for anyone else to use/improve. You will obviously have to enable PHP on the template and replace the segment numbers to suit your own site, I have only shown these as they are relevant to the site we are working on…

    <?php
    $this->EE =& get_instance();
    $seg3 = $this->EE->uri->segment(3);
    $seg4 = $this->EE->uri->segment(4);
    if ($seg3 <> ''){
        $nextYearLink = ((int)$seg3+1).'/'.$seg4;
        $prevYearLink = ((int)$seg3-1).'/'.$seg4;    
    } else {
        $nextYearLink = (date('Y')+1).'/'.date('m');
        $prevYearLink = (date('Y')-1).'/'.date('m');
    }
    ?>
    
    <tr class="calendarHeader">
        <th><div class="calendarMonthLinks"><a href="http://{path=%27pages/calendar%27}/&lt?php"><<</a></div></th>
        <th><div class="calendarMonthLinks"><a href="http://{previous_path=pages/calendar}"><</a></div></th>
        <th colspan="3">{date format="%F %Y"}</th>
        <th><div class="calendarMonthLinks"><a href="http://{next_path=pages/calendar}class=calendarMonthLinks">></a></div></th>
        <th><div class="calendarMonthLinks"><a href="http://{path=%27pages/calendar%27}/&lt?php">>></a></div></th>
    </tr>

    (Watch for the anchor text, it is entered in the template using character codes, but in the code view on the forums it renders the greater/less than character!)

    If anyone can suggest any problems or improvements, please do so!

    Cheers,

  • #6 / Oct 14, 2010 10:43am

    Sue Crocker

    26054 posts

    Thanks for posting your solution, Gordon. I’m going to move this to the CodeShare Corner in case anyone else wants to chime in. Please also consider adding it to the EEWiki.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases