Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

Anyone know how to "unlink" the {next_path} or {previous_path} for {exp:channel:calendar} if there aren't any entries for the next or previous month when building the mini-calendar?

share|improve this question
    
I see that this was tagged with Solspace Calendar, but it refers to the first-party tag. Is this correct? If so, I think the question should be revised to include this. And if not, the Solspace tag should be removed. –  Justin Kimbrell Dec 15 '12 at 15:34
    
Is this question about the Solspace Calendar Module or the native EE calendar option? Please clarify or we will need to remove the question. –  Anna_MediaGirl Dec 16 '12 at 6:53
    
I've removed the Solspace tag since it's clear from the question body they are using the native EE calendar. –  Adrian Macneil Dec 24 '12 at 18:40
add comment

1 Answer 1

up vote 4 down vote accepted

I had an answer for this on the EE Wiki, but can't see that it exists anymore -- even the Wayback Machine can't find it. So, here is some EE template source which will show you how to do it, which I've used for years on a site - I believe it will fit EE1 as well as EE2.

The principle is to use database queries via the EE Query module - be sure to have it enabled. If I were doing this today, I would probably make an add-on to allow the code to be simpler to look at.

It works well, however, just to embed the queries as we're writing out the calendar. We look for whether there are later (or earlier) entries. If there are, we write out the link, visibly showing appropriate corner brackets which make the buttons. If there aren't, we write nothing, leaving a blank cell, which looks right.

Notes:

-- this solution is for the first-party (EE tag) calendar. It seems to me that's what's referenced in the question, and you should remove the solspace-calendar tag if that's so, per Anna's request. If it is for Solspace Calendar, you should then say so, and maybe the queries here will also be useful, since I imagine you could play a similar trick.

-- the queries here are on exp_channel_titles, which fits EE2.x. That will be exp_weblog_titles if you are on EE1. If you used a database prefix, you'll have to include that too - the queries may only reference real table names in the database. There are ways to get that, but they seem not worth the complication for this case.

-- further on the query, note that I'm hard-coding channel_id = '6'. You can look up the channel_id number for the channel you want by using the EE control panel Tool>SQL Manager>Manage Database Tables, and clicking Browser for the table exp_channels.

-- there isn't much of a measurable performance hit using this method, among all the other queries which typically build a web page. If you want things to go really fast on a shared hosting, you can look into CE Cache, which is simple excellent.

-- the calendar tag used this way is one of the cases where you actually do want to have dynamic='yes', so that it follows the main channel entry you are showing.

-- if you're actually using some other kind of buttons, it's likely the queries should be used to set CSS labels to make them normally formatted or invisible, to achieve the effect you've asked for.

-- yes, it's a table -- that's the old EE way. Perhaps one place where tables actually make sense, since a calendar is one.

Good fortune, and nice holidays to all involved.

<h2 class="sidetitle">History</h2>
<br />
<div id="calendar"> 
 {exp:channel:calendar switch="calendarToday|calendarCell" channel="{my_channel}" dynamic="yes" show_pages="no" }
  <table class="calendarBG" border="0" cellpadding="5" cellspacing="1" summary="My Calendar">
    <tr>
      <th class="calendarHeader"><div class="calendarMonthLinks"> 
        {exp:query sql="SELECT year, month FROM exp_channel_titles where status = 'open' and channel_id = '6' and ((year = {date format="%Y"} and month < {date format="%n"}) or year < {date format="%Y"}) order by year desc, month desc limit 1;" } <a href="{path={my_template_group}/articles_all/{year}/{month}}">&lt;&lt;</a> {/exp:query}
        </div></th>
      <th class="calendarHeader" colspan="5">{date format="%F %Y"}</th>
      <th class="calendarHeader"><div class="calendarMonthLinks"> 
        {exp:query sql="SELECT year, month FROM exp_channel_titles where status = 'open' and channel_id = '6' and ((year = {date format="%Y"} and month > {date format="%n"}) or year > {date format="%Y"}) order by year asc, month asc limit 1;" } <a href="{path={my_template_group}/articles_all/{year}/{month}}">&gt;&gt;</a> {/exp:query}
        </div></th>
    </tr>
    <tr> {calendar_heading}
      <td class="calendarDayHeading">{lang:weekday_abrev}</td>
      {/calendar_heading} </tr>
    {calendar_rows }
    {row_start}
    <tr>{/row_start}
      {if entries}
      <td class='{switch}' align='center'><a href="{day_path={my_template_group}/articles_all}">{day_number}</a></td>
      {/if}
      {if not_entries}
      <td class='{switch}' align='center'>{day_number}</td>
      {/if}
      {if blank}
      <td class='calendarBlank'>&nbsp;</td>
      {/if}
      {row_end}</tr>
    {/row_end}
    {/calendar_rows}
  </table>
  {/exp:channel:calendar} 
</div>
share|improve this answer
1  
Awesome, thanks for sharing your solution here! –  Adrian Macneil Dec 24 '12 at 18:41
add comment

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.