Newscoop 4 Cookbook

Ways to create archives

There are different approaches to creating archives. It can be:

  • a list of Articles
  • a list of Issues
  • a list of PDF versions
  • a list of Polls
  • a calendar of Articles / Issues / PDF versions
  • a search form to look through all materials

You would usually combine different options or make your own, depending on your needs.

General Archive type based on Issues

This is a very basic and widely used type of Archive. It is convenient even if you have many issues. You can see an example in our "Journal" template package:

<div id="accordion"> {{ list_issues constraints="number not 1" order="bypublishdate desc" }}   <h3 style="margin-bottom: 20px"><a href="#">{{ $gimme->issue->name }}</a></h3>     <div> {{ list_sections }} {{ list_articles }} {{ if $gimme->current_articles_list->at_beginning }}       <h4><a href="{{ uri options="section" }}">{{ $gimme->section->name }}</a></h4>         <ul> {{ /if }}           <li><a href="{{ uri options="article" }}">{{ $gimme->article->name }}</a> - {{ $gimme->article->publish_date|camp_date_format:"%e %M %Y" }} - {{ $gimme->article->comment_count }} comment(s)</li> {{ if $gimme->current_articles_list->at_end }}         </ul> {{ /if }} {{ /list_articles }} {{ /list_sections }}     </div> {{ /list_issues }} </div><!-- /#accordion --> 

And after adding just a few lines of jQuery code you get a nice accordion effect:

$(function() {   $( "#accordion" ).accordion(); }) 

The result will look like this:

Combination of different types of Archives

If you have lots of issues, and especially if you plan to maintain the Archive for a long time, you might want to have a combination of different types of archives. You can take a look at an example of how it's done at: http://ganc-chas.by/by/page/archive

Implementing a search-based archive is a good practice, as it gives your readers the opportunity to find the required material in a click. We use an Advanced Search form for that purpose (please take a look at the Template Reference for more information about Advanced Search).

archive-search-form.tpl

<div id="archive_search_form"> <form method="post" action="{{uri}}" name="search_articles"> <input type="hidden" value="{{$gimme->template->identifier}}" name="tpl" /> <input type="hidden" value=true name="f_search_articles" /> <fieldset>         <div><label>Find:</label><input type="text" value="{{$gimme->search_articles_action->search_phrase}}" name="f_search_keywords" /></div>         <div><label>Search by:</label>     <span>       <input type="radio" name="f_search_scope" value="content" checked="checked" /> text &nbsp;       <input type="radio" name="f_search_scope" value="title" /> title &nbsp;       <input type="radio" name="f_search_scope" value="author" /> author     </span>   </div>         <div><label>Issue:</label>{{camp_select object="search" attribute="issue"}}</div>         <div><label>Date:</label><input type="text" id="f_search_start_date" name="f_search_start_date" /><input type="text" id="f_search_end_date" name="f_search_end_date" /></div>         <div><input type="submit" class="button-greent1" name="f_search_articles" value="Find" /></div> </fieldset> </form> </div> 

To make other search controls (please read the chapter on Using Calendars) and control the looks and flow we utilize jQuery a lot:

functions.js

/* Archive search form & results */  $("form[name=search_articles] select[name=f_search_issue] option[value=1]").remove(); /* remove first issue from the list */ // Submitting a form $('#archive_search_form .button-greent1').live("click",function(){   var url = $('#archive_search_form form[name=search_articles]').attr("action") + '?tpl=archive-search-results.tpl';   var form = $('#archive_search_form form[name=search_articles]').serialize();   $.post(url, form, function(data){$('#archive_search_results').html(data);});   return false; });  /* Datepickers */  // Load results with AJAX if a date was clicked in a calendar $("#ArticleArchive .ui-state-highlight a").live("click",function(){   $("#archive_search_results").load( $(this).attr("href") + '&tpl=archive-search-results.tpl' );   return false; });  var cs_date;var pdf_date; $.ajax({async:false,dataType:'json',url:'/templates/js/calendar-items.json',success: function(d){cs_date=d;}}); $.ajax({async:false,dataType:'json',url:'/templates/js/pdf-items.json',success: function(d){pdf_date=d;}});  // Article Archive Calendar $("#ArticleArchive").datepicker({   changeMonth: true,   changeYear: true,   beforeShowDay: function(d){     var date = $.datepicker.formatDate("yy-mm-dd",d);     var link = "page_url?date="+date;     show=false;;caption="";     if ($.inArray(date,cs_date.article)!=-1){       var x=0;       $.grep(cs_date.article,function(n,i){if(n==date) x++;});       show=true;style="ui-state-highlight active";caption+="Articles found: "+x;     }     return [show,style,caption,link];   } });  // PDF Archive Calendar $("#PDFArchive").datepicker({   changeMonth: true,   changeYear: true,   beforeShowDay: function(d){     var date = $.datepicker.formatDate("yy-mm-dd",d);     show=false;;caption="";link="#";     if (pdf_date.pdf[date]){       show=true;       style="ui-state-attention active";       caption=pdf_date.pdf[date].title;       link=pdf_date.pdf[date].link;     }     return [show,style,caption,link];   } }); 

And the whole process is going on in one template, which receives data and provides output.

archive-search-results.tpl

First, we need to check if the date parameter was supplied. In this case, we provide a list of articles published on that date:
{{if $smarty.get.date}} {{assign var="get_date" value=$smarty.get.date|camp_date_format:"%Y-%m-%d"}}   <div class="header-diag">     Materials on: {{$get_date|camp_date_format:"%e %M %Y"}}   </div> 
We are trying to look for articles on a given date in sections that contain articles of type 'article':
  {{list_articles columns="15" constraints="type is article issue greater 1 section smaller_equal 120 publish_date is `$get_date`"}}     {{if $gimme->current_list->count > 15}}{{assign var="navigation" value=true}}{{/if}}   {{if $gimme->current_list->row==$page}}     {{if $gimme->current_list->column==1}}       <dl class="b-comm">     {{/if}}       {{if $gimme->section->name != $section}}<dt>{{$gimme->section->name}}</dt>{{/if}}         <dd><a href="{{uri}}">{{$gimme->article->name}}</a></dd>       {{assign var="section" value=$gimme->section->name}}     {{if $gimme->current_list->column==15}}       </dl>     {{/if}}   {{/if}}   {{/list_articles}}   {{if $gimme->prev_list_empty}}<em>Nothing was found.</em>{{/if}} 

Otherwise, if there was a search action, we should output search results:

{{elseif $gimme->search_articles_action->defined}}  <div class="header-diag">Search results {{if $gimme->search_articles_action->search_phrase}}for "{{$gimme->search_articles_action->search_phrase}}"{{/if}}</div>    {{list_search_results columns="10" order="bypublishdate desc"}}     {{if $gimme->current_list->column==1}}       <dl class="b-comm">     {{/if}}         <dt><span><a href="{{uri}}">{{$gimme->article->name}}</a></span>&nbsp;(#{{$gimme->issue->name}}({{$gimme->issue->number}}) {{$gimme->article->publish_date|camp_date_format:"%d.%m.%Y"}})</dt>         <dd>{{$gimme->article->intro|strip_tags:false|strip|truncate:300}}</dd>     {{if $gimme->current_list->column == 10}}       </dl>     {{/if}}   {{/if}}   {{/list_search_results}}   {{if $gimme->prev_list_empty}}<em>Nothing was found.</em>{{/if}} 

Else, if there's no search action or date provided, just output the list of articles in the current and previous issues:

{{else}}    <div class="header-diag">Latest materials</div>   <dl class="ui-accordion ui-widget">      <dt class="ui-accordion-header ui-state-default">Last Issue</dt>     <dd class="ui-accordion-content">     {{local}}{{set_current_issue}}{{assign var="issn" value=$gimme->issue->number}}{{/local}}     {{list_articles constraints="type is article issue is $issn section smaller_equal 120"}}       {{if $gimme->section->name != $section}}{{if $gimme->current_list->index>1}}<br />{{/if}}<p><strong>{{$gimme->section->name}}</strong></p>{{/if}}       <p><a href="{{uri}}">{{$gimme->article->name}}</a></p>       {{assign var="section" value=$gimme->section->name}}     {{/list_articles}}     {{if $gimme->prev_list_empty}}<p>Nothing was found.</p>{{/if}}     </dd>      {{list_issues length="1" constraints="number smaller $issn" order="byPublishDate desc"}}     <dt class="ui-accordion-header ui-state-default">Previous Issue</dt>     <dd class="ui-accordion-content">     {{list_articles constraints="type is article section smaller_equal 120"}}       {{if $gimme->section->name != $section}}{{if $gimme->current_list->index>1}}<br />{{/if}}<p><strong>{{$gimme->section->name}}</strong></p>{{/if}}       <p><a href="{{uri}}">{{$gimme->article->name}}</a></p>       {{assign var="section" value=$gimme->section->name}}     {{/list_articles}}     {{if $gimme->prev_list_empty}}<p>Nothing was found.</p>{{/if}}     </dd>     {{/list_issues}} 

In this example we are also listing the latest PDF issues and Polls:

    <dt class="ui-accordion-header ui-state-default">Latest PDF versions</dt>     <dd class="ui-accordion-content">       {{list_articles constraints="type is pdf issue greater 1 section is 300 publish_date greater 1900-01-01"}}{{list_article_attachments length="1"}}         <a href="http://{{$gimme->publication->site}}{{uri options="articleAttachment"}}">PDF #{{$gimme->issue->name}}({{$gimme->issue->number}}) / {{$gimme->issue->publish_date|camp_date_format:"%d.%m.%Y"}}</a><br />       {{/list_article_attachments}}{{/list_articles}}     </dd>      <dt class="ui-accordion-header ui-state-default">Latest Polls</dt>     <dd class="ui-accordion-content">       {{list_polls length="3" order="bynumber desc"}}         {{if $gimme->current_list->index>1}}<br /><br />{{/if}}<p><b>{{$gimme->poll->question}}</b></p><br />         {{list_poll_answers}}<p>         <div>{{$gimme->pollanswer->answer}}           <div class="poll-result ui-state-highlight" style="width:{{$gimme->pollanswer->percentage|string_format:"%d"}}%;">{{$gimme->pollanswer->percentage|string_format:"%d"}}%</div>         </div></p>         {{/list_poll_answers}}       {{/list_polls}}     </dd>    </dl> {{/if}} 

And that's pretty much it!

Definitely, you should think in advance about what type of archive you will need. After ten years of work, you would still like to have everything in good order.