[4.0.3] Number of articles in a topic
  • Hello,

    {{ en }}

    I would like to display in article template (article.tpl) the topic (topics) the article is attached to, along with the number of articles in that topic. For example (number of article is in the brackets):

    A long title for an artile
    Published in Category / Subject(s): Subject 1 (5), Subject 2 (3)

    {{ /en }}

    {{ ro }}

    Aş vrea să afişez în pagina articolului (article.tpl) subiectul (subiectele) articolului, împreună cu numărul articolelor cu acelaşi subiect. De exemplu (numărul articolelor e în paranteze):

    Un titlu lung pentru articol
    Publicat în Categorie / Subiect(e): Subiect 1 (5), Subiect 2 (3)

    {{ /ro }}

    {{ ru }}

    Я хотел бы показать в шаблоне статьи  (article.tpl) тему (темы) статьи , наряду с количеством статей по данной теме. Например (номер статьи в скобках):

    Длинное название для
    статьи
    Опубликовано в Категории / Тема(ы): Тема 1 (5), Тема 2 (3)

    {{ /ru }}



    Thank you.
  • 4 Comments sorted by
  • Hi Nalyk,

    You can display the list of topics an article is attached to by placing something like this in your article template:

    {{ $gimme->article->title }}
    {{ list_article_topics }}
        {{ if $gimme->current_list->at_beginning }}
            Published in Category / Subject(s):
        {{ /if }}
        {{ $gimme->topic->name }}{{ if !$gimme->current_list->at_end }}, {{ /if }}
    {{ /list_article_topics }}

    ... unfortunately, there is no a direct way currently in Newscoop's template engine to display the number of articles per topic. To achieve that you would have to work around the code, if you feel like coding and contributing we could assist you :-)

    All Best,

  • Vote Up0Vote Down Martin SaturkaMartin Saturka
    Posts: 40Member, Sourcefabric Team
    Hi Nalyk,
    you may want to put in an inner list inside the "list_article_topics":

    {{ assign var="topic_name" $gimme->topic->name }}
    {{ list_articles constraints="topic is $topic_name" length=1 }}
        {{ assign var="topic_count" $gimme->current_list->count }}
    {{ /list_articles }}

    The "length=1" is there for avoiding performance issue; the "count" is the total one.

    For the topic_name, you may want to append ":en" (or respective language specifier), and escape spaces with backslashes.

    If this double-list structure would not work, try to put the topic names into an array first, then just utilize that array.

  • I used this code, and it works:

      {{ list_article_topics }}
              <a href="{{ uri }}">{{$gimme->topic->name }}</a>
              {{ set_topic name="$gimme->topic->name:$gimme->language" }}
              {{ list_articles ignore_issue="true" ignore_section="true" }}
                ({{ $gimme->current_list->count }})
              {{ /list_articles }}
      {{ /list_article_topics }}

    But, in some cases, it displays the number twice and, unfortunately, i can not manage to understand why.
  • Hey, as Martin suggested, use length="1" for list_articles. And you don't need that set_topic line, the current topic in the list will be used by list_articles.