Sourcefabric Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Newscoop 4.1 Cookbook

Subsections

Although subsections are not officially supported by the default Newscoop installation there are a number of ways with which to emulate parent/child node behaviour.

Using these solutions is considered advanced template editing.

The Sourcefabric way

Using Topics

Using topics is our preferred method as it is the easiest and simplest to implement and maintain.

This method relies on creating a parent topic, then creating new topics for use as subcategories. This has the added benefit of being able to have articles in multiple categories without the need for duplication and that support for translations is automatic.

In this example we're assuming you have created a main topic called 'Subsections' to hold all of your sub sections already.

A setup something like this would be sufficient:

Subsections
  News
  Business
  Politics
  Sport 

Navigation

To create a navigation element from the newly created topics you will have to do something like the following which supports two levels of nested subcategories:

{{ set_topic name="Subsections:en"}} or {{ set_topic identifier="<Topic ID>" }}
  {{ list_subtopics }}
    {{ if $gimme->current_list->at_beginning }}
      <ul>
    {{/if}}
       <li {{if $gimme->default_topic->identifier == $gimme->topic->identifier}} class="active" {{/if}} >
          <a href="{{ url options='section' }}?tpid={{$gimme->topic->identifier}}">{{ $gimme->topic->name }}</a>
{{ list_subtopics }}
           {{ if $gimme->current_list->at_beginning }}
             <ul>
           {{/if}}
               <li {{if $gimme->default_topic->identifier == $gimme->topic->identifier}} class="active" {{/if}} >
                     <a href="{{ url options='section' }}?tpid={{$gimme->topic->identifier}}">{{ $gimme->topic->name }}</a>
               </li>
          {{ if $gimme->current_list->at_end }}
            </ul>
          {{ /if }}
        {{ /list_subtopics }}
</li>
     {{ if $gimme->current_list->at_end }}
     </ul>
     {{ /if }}
   {{ /list_subtopics }}
<!-- here we reset topic back to default_topic. Otherwise our menu code would affect article list -->
{{ set_default_topic }}
 

More subsection methods

Although the following approaches have been tried and tested they also are considered 'hacks' so please proceed with caution if you feel as though the above solution is inappropriate.

Using Issues

If your site is not being structured in a way that requires regular issues it might be possible to restructure your content using issues as your section level content containers and then those sections held within them become subsections.

Navigation

The default Newscoop functionality does not support using issues as navigation but with a little gentle massaging it will do it.

{{ unset_issue }}
{{ list_issues }}
  <li><a href='{{ url options="issue" }}'>{{ $gimme->issue->name }}</a>
    <ul>
    {{ list_sections order="bynumber asc" }}
      <li><a href="{{ url options='section' }}">{{ $gimme->section->name }}</a></li>
    {{ /list_sections }}
    </ul>
  </li>
{{ /list_issues }}
 

Using Custom Switches

This is the most advanced way of creating subsections. Good thing about it is that You can use all solutions in the same time. There may be some situation when using custom switches will be helpful. One of those is when You want to list articles containing media like slideshows or videos. Using switches makes it really flexible because You can point that article with embedded Youtube should appear on "videos" listing page.

Let's assume that we want to create "Multimedia" section with audio on video subsections. We also assume that "audio" and "video" switches are already configured in used article type. 

Navigation 

<!-- we list all sections to create regular navigation -->
{{list_sections ...}}
   <!-- if loop will reach multimedia section we want to add those two subsections based on switches -->
   {{if $gimme->section->number==<MULTIMEDIA_SECTION_NUMBER>}}
        <ul>
           <li><a href="{{ url options="section" }}?media=video" >Video</a></li>
<li><a href="{{ url options="section" }}?media=audio" >Audio</a></li>
        </ul>
   {{/if}}
{{/list_sections}}
 

Template for multimedia section

What we need to do here is to retrieve media variable from GET array.

{{assign var="media_get" value=$smarty.get.media}}

{{if $media_get=="audio" || $media_get=="video"}}

    {{ assign var="publish_cond" value="`$media_get` is on" }}

{{else}}

   {{ assign var="publish_cond" value=" " }}

{{/if}}

Now we will use publish_cond variable to filter article list.

{{ list_articles  [...]  constraints="$publish_cond"}}
      ...
{{/list_articles}}
 

Numeric trick for sub-section solution

Another way of dealing with subtopics may be to simulate subtopic functionality with decade numbers for root topics, and the rest in between full decade numbers may represent subtopics. In other words, we can have something like this:

sec no. root section sub-section
10 Politics  
11   Domestic
12   Regional
13   International
20 Economy  
21   Agriculture
22   Coal-mining
30 Culture  
31    Applied arts
32     Gallery life
33     Celebrity gossip
34   Sculpture 
40  Sports   
41   Football 
42   Other sports 
50 Lifestyle   
51    Cooking and dining
52     Urban gardening
53    Cherry picking 

This structure may be used in templates in a way that on the root sections level we list only those divisible by zero, and as its subsctions those that follow - to the next number divideable by ten. (If you need really lot of subsections per root section, consider using divisins by 100 :) ). So, next code is just an example how we can use this approach

{{ assign var="secno" value=10 }}
<ul>
{{ while $secno < 60 }}
{{ assign var="nextsecno" value=$nextsecno+10 }}
{{ set_section number=$secno }}
<li><a href="{{ url options="section" }}">{{ $gimme->section->name }}</a></li>
<ul>
{{ list_sections constraints="number gt $secno number lt $nextsecno }}
 <li class="subsection"><a href="{{ url options="section" }}">{{ $gimme->section->name }}</a></li>
{{ /list_sections }}
</ul>
{{ $secno = $secno+10 }}
{{ /while }}
</ul>

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.