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.

Yet Another Calendar Question!

September 25, 2007 12:03am

Subscribe [0]
  • #1 / Sep 25, 2007 12:03am

    jschutt

    452 posts

    Here’s a question for all you brilliant EE’ers.  I am using the default code from the docs to create the “Big Calendar”. 

    Everything is up and working correctly. 

    What I would like to try and do is create a list of, say, the next 6 months so that the user can jump from September to January without having to click the “Next Month” link. 

    Does that make sense?

    Thanks for your help!

  • #2 / Sep 25, 2007 8:42am

    e-man

    1816 posts

    Do you mean adding a list of links (easy) or adding 6 tables (hard) to the page?

  • #3 / Sep 25, 2007 9:46am

    jschutt

    452 posts

    You know how the “Big Calendar” looks like this on the top row - <<  September >>

    I would like to make it do this - <<  Sep Oct Nov Dec Jan Feb   >> - with each of those months being links to the corresponding calendar. 

    My client is saying that it is just too difficult to navigate from month to month.

    E-man, I actually was looking at one of your sites, Retina Dance Company, to see how you were using the calendar!  Funny you should be the first to reply!

  • #4 / Sep 25, 2007 9:52am

    e-man

    1816 posts

    Since the url’s for the calendar generally take this form:

    <a href="http://www.mysite.com/index.php/calendar/2007/9/">http://www.mysite.com/index.php/calendar/2007/9/</a>

    the url’s for the next few months would look like this:

    <a href="http://www.mysite.com/index.php/calendar/2007/9/">http://www.mysite.com/index.php/calendar/2007/9/</a>
    <a href="http://www.mysite.com/index.php/calendar/2007/10/">http://www.mysite.com/index.php/calendar/2007/10/</a>
    <a href="http://www.mysite.com/index.php/calendar/2007/11/">http://www.mysite.com/index.php/calendar/2007/11/</a>
    etc…

    I’m sure the PHP gurus here on the forum can whip up something to auto-generate the next 6 links in an HTML unordered list. Any takers? 😊

  • #5 / Sep 25, 2007 10:08am

    jschutt

    452 posts

    I’m sure the PHP gurus here on the forum can whip up something to auto-generate the next 6 links in an HTML unordered list. Any takers?

    Now we’re talking!

  • #6 / Sep 25, 2007 11:07am

    e-man

    1816 posts

    Ok I tested this in one of Retina’s templates and it works fine. No doubt more experienced php-coders will chuckle but hey 😊
    This will output the links to the next 6 months in an unordered list and presupposes this url structure for your calendar: http://www.mysite.com/index.php/calendar/2007/9/.

    <?php 
        $month = trim("{segment_3}", 0); // trim leading 0
        $year = "{segment_2}";
        $base_url = "http://www.mysite.com/index.php/calendar/"; // for convenience sake, add your own url here
        $the_months = array("","january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"); //names of the months, first empty element takes care of the 0 counter
        ?>
        <ul>
        <?php
        for ($i=0; $i < 6 ; $i++) { 
            echo "<li><a >"."$the_months[$month]"."</a></li>";
            $month++;
                if ($month > 12) {
                    $month=1;
                    $year++;
                };
        }
        ?>
        </ul>
  • #7 / Sep 25, 2007 11:10am

    jschutt

    452 posts

    This is why I love EE - Community Help!  Thanks so much.  I will try this out and let you know how it works.

  • #8 / Sep 25, 2007 1:38pm

    jschutt

    452 posts

    This code will output the months like we talked about, but it always starts with January.  Is there a way to have it do the following six months from now?

    EDIT -

    The reason that it is always starting in January is because I am linking to http://www.mysite.com/index.php/calendar

    There is no {segment_2} or {segment_3} to build the links around.

  • #9 / Sep 25, 2007 2:04pm

    jschutt

    452 posts

    Another issue that I noticed is this - You called {segment_2}, which is normally the year.  In my case, I linked to http://www.mysite.com/index.php/calendar because my calendar is in the index page.  The links that are generated give this: http://www.mysite.com/index.php//2 because there is no {segment_2} when they are created. 

    How should I fix this?

  • #10 / Sep 25, 2007 2:20pm

    Nutmeg

    111 posts

    What I would like to try and do is create a list of, say, the next 6 months so that the user can jump from September to January without having to click the “Next Month” link. 

    Do you need the next 6 months to show regardless if there are any entries being made in any of these months?

  • #11 / Sep 25, 2007 2:25pm

    jschutt

    452 posts

    Yes, I would like them to show even if there aren’t any entries.

  • #12 / Sep 25, 2007 2:33pm

    e-man

    1816 posts

    I had to dig through the templates again (it’s been a while) but I remembered that for the Retina site I sort of hardwired those 2 segments in the link to the calendar like this:

    <a href="http://www.retinadance.com/index.php/calendar/&lt?php">event calendar</a>

    This is the link I use in the main navigation, the two php statements echo the current year and month. Hope this helps…

  • #13 / Sep 25, 2007 2:41pm

    jschutt

    452 posts

    That helped bring the months into the correct order.  There are some anomalies with how certain months are linking.  For example, when I click on the link generated for October, the months then reset to January being first.  I would guess that has to do with October being the 10th month. 

    Also, when I click on months that are just single numbers (jan - sep) the link isn’t working.  Is that because EE needs them with a leading 0?

    Thanks very much for your help with this!

  • #14 / Sep 25, 2007 3:22pm

    e-man

    1816 posts

    Try this version I used ltrim instead of trim and it now checks if it needs to add a trailing 0 if the number is between 1 -9. I tested this and it works fine.
    See if this version does the trick:

    <?php 
        $month = ltrim("{segment_3}", 0); // trim leading 0
        $year = "{segment_2}";
        $base_url = "http://www.yoursitehere.com/index.php/calendar/"; // for convenience sake, add your own url here
        $the_months = array("","january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"); //names of the months, first empty element takes care of the 0 counter
        ?>
        <ul>
        <?php
        for ($i=0; $i < 6 ; $i++) { 
            if ($month<10) {
                echo "<li><a >"."$the_months[$month]"."</a></li>";
            } else {
                echo "<li><a >"."$the_months[$month]"."</a></li>";
            }
            $month++;
                if ($month > 12) {
                    $month=1;
                    $year++;
                };
        }
        ?>
        </ul>
  • #15 / Sep 25, 2007 3:48pm

    jschutt

    452 posts

    Now it’s working!  This is exactly what I was looking for!

    Just a thought - how would you modify this to have three months before the shown calendar and three months after?  Like this - June July August September October November December

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

ExpressionEngine News!

#eecms, #events, #releases