Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Heading for Archive View


Reply


3 Posts   1199 Views

Avatar
jdj

Community Member, 3 Posts

16 July 2009 at 4:52pm

In the BlogHolder template, there is conditional to display the page title or to change this if viewing tabs:

<% if Tag %>
   <h1><% _t('VIEWINGTAGGED', 'Viewing entries tagged with') %> '$Tag'</h1>
<% else %>
<h1>$Title</h1>
<% end_if %>

Is there a way to do this for archives by date? I haven't found anything in the docs.

Avatar
Juanitou

Community Member, 323 Posts

23 July 2009 at 1:05am

Hi! You're not alone I'm also trying to do it. Hope someone helps!

Avatar
Juanitou

Community Member, 323 Posts

23 July 2009 at 2:12am

Edited: 23/07/2009 2:36am

I found it!

In BlogHolder_Controller:

function archive() {
   if(is_numeric(Director::urlParam('Action'))) {
      $year = Director::urlParam('Action');
      $month = Director::urlParam('ID');

      if($month && is_numeric($month) && $month >= 1 && $month <= 12 && is_numeric($year)) {
         $date = new Date('Date');
         $date->setValue(array(
            'Day' => 1,
            'Month' => $month,
            'Year' => $year
         ));
         $output =new DataObjectSet();
         $output->push(new ArrayData(array(
            'Date' => $date
         )));
         return $output;
      } else if(is_numeric($year)) {
         $date = new Date('Date');
         $date->setValue(array(
            'Day' => 1,
            'Month' => 1,
            'Year' => $year
         ));
         $output =new DataObjectSet();
         $output->push(new ArrayData(array(
            'Date' => $date->Year()
         )));
         return $output;
      } else {
         return array();
      }
   }
}

Then in BlogHolder.ss:

…
<% if archive %>
<% control Archive %>
   <h3 id="ViewingArchived"><% _t('VIEWINGARCHIVED', 'Viewing entries published on') %> <% if Date.Month %>$Date.FormatI18N(%B %Y)<% else %>$Date<% end_if %></h3>
<% end_control %>
<% end_if %>
…

Don't ask me why it is necessary to use a DataObjectSet instead of a simple array: the latter didn't worked. I'm sure there's a lighter and smarter way to do it.

Regards,
Juan