× Warning! This forum is in archival status. New contributions may not work.
Listing all multimedia in a mixed list.
  • Hi!

    I have a question, is there a way to list all the multimedia (video, audio and pictures) so I can be able to merge them into something like the screenshot below where audio, video and pictures are mixed together ordered by date and not separated between media type?

    Thanks in advance.

    image
  • 8 Comments sorted by
  • Vote Up1Vote Down Micz FlorMicz Flor
    Posts: 184Administrator
    This does it. I commented the code. The logic: first list a larger number of articles for media. Put a limited number in an array. Then you can use this array to list the articles with the list_article statement, which is needed to get access to the image renditions.

    {{* assign counter and maximum count for collecting multimedia files *}}
    {{assign var=multimediacounter value=0}}
    {{assign var=multimediacountermax value=10}}
    {{ list_articles length="100" ignore_issue="true" ignore_section="true" order="bypublishdate desc" }}
      {{* check if we have to do anything => not yet hit maximum *}}
      {{if $multimediacounter lt $multimediacountermax}}
          {{* assign variable for current article. 1 => has multimedia *}}
          {{assign var=multimediacurrent value=0}}
          {{ foreach $gimme->article->slideshows as $slideshow }}
            {{assign var=multimediacurrent value=1}}
          {{ /foreach }}
          {{ if $gimme->article->has_attachments }}
              {{ list_article_attachments }}
                  {{ if $gimme->attachment->extension == oga }}    
                    {{assign var=multimediacurrent value=1}}              
                  {{ elseif $gimme->attachment->extension == ogv || $gimme->attachment->extension == ogg || $gimme->attachment->extension == mp4 || $gimme->attachment->extension == webm }}             
                    {{assign var=multimediacurrent value=1}}
                  {{ /if }}  
              {{ /list_article_attachments }}   
          {{ /if }}  
          {{* check now if multimedia found *}}
          {{if $multimediacurrent == 1}}
            {{* add to array with multimedia articles *}}
            {{append var=multimedia value="yes" index="`$gimme->article->number`"}}
            {{* increase counter to check for max number *}}
            {{$multimediacounter++}}
          {{/if}}
      {{/if}}
    {{ /list_articles }}  
    {{* spit out what we found *}}
    {{$multimedia|@print_r}}
    {{* this is the resulting article list *}}
    {{foreach from=$multimedia key=articleID item=articleName}}
        {{ list_articles ignore_issue="true" ignore_section="true" length="1" constraints="number is `$articleID`"}}
          <li>Section:{{ $gimme->section->name }} | ID:{{$articleID}}: {{ $gimme->article->name }}</li>
        {{ /list_articles }}
    {{/foreach}}

    Post edited by Micz Flor at 2013-04-17 10:15:03
  • Vote Up0Vote Down Micz FlorMicz Flor
    Posts: 184Administrator
    please as the themes list.
    Sorry, this is the right place of course :) I thought it came directly via email.
    Post edited by Micz Flor at 2013-04-17 02:57:41
  • I usually do it with switch. So any article with switch set to on is visible in multimedia list. That way You can easily choose what You want to show even if there is youtube embed in article body. 

    Code for listing will look like:
    {{list_articles ignore_section="true" constraints="multimedia is on"}}

    where "multimedia" is the name of the switch.
  • Vote Up0Vote Down Micz FlorMicz Flor
    Posts: 184Administrator
    I believe it should be possible to write a little smarty magic with assigning vars running through these loops and collect what is a multimedia article. I have no time to do it right now. Possibly in the afternoon.

    {{ foreach $gimme->article->slideshows as $slideshow }}
    {{ /foreach }}
    {{ if $gimme->article->has_attachments }}
      {{ list_article_attachments }}
        {{ if $gimme->attachment->extension == oga }}          
        {{ /if }}     
      {{ /list_article_attachments }}  
    {{ /if }} 
  • Hi.

    A quick update, I've made it work but there is one issue with the code in the line: 

     {{$multimediacounter++}}

    that will print out the counter into the template generating numbers like 0 1 2 3 4 .. on the top of the multimedia slider, is there a way to use the ++ increment and not print it out?

    Tried by assigning again but it did not worked. 

    Thanks.
  • Vote Up0Vote Down Micz FlorMicz Flor
    Posts: 184Administrator
    :) true. I will send you something later today.
    Post edited by Micz Flor at 2013-04-25 06:55:05
  • Did you try {{ assign var="multimediacounter" value=$multimediacounter+1 }}

    according to Smarty 3 manual (http://www.smarty.net/docs/en/language.function.assign.tpl) this should work too

    {{ assign "multimediacounter" $multimediacounter+1 }}

    and probably this

    {{ assign "multimediacounter" $multimediacounter++ }}


    --
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric
    ljuba.rankovic@sourcefabric.org

    http://www.sourcefabric.org
    http://www.twitter.com/Sourcefabric
  • Vote Up0Vote Down Micz FlorMicz Flor
    Posts: 184Administrator
    Yes, Ljuba is right and this is the resulting code:

    {{* assign counter and maximum count for collecting multimedia files *}}
    {{assign var=multimediacounter value=0}}
    {{assign var=multimediacountermax value=10}}
    <h3>Alle Artikel</h3>
    {{ list_articles length="100" ignore_issue="true" ignore_section="true" order="bypublishdate desc" }}
      {{* check if we have to do anything => not yet hit maximum *}}
      {{if $multimediacounter lt $multimediacountermax}}
        {{* assign variable for current article. 1 => has multimedia *}}
        {{assign var=multimediacurrent value=0}}
        {{ foreach $gimme->article->slideshows as $slideshow }}
          {{assign var=multimediacurrent value=1}}
        {{ /foreach }}
        {{ if $gimme->article->has_attachments }}
          {{ list_article_attachments }}
            {{ if $gimme->attachment->extension == oga }}   
              {{assign var=multimediacurrent value=1}}             
            {{ elseif $gimme->attachment->extension == ogv || $gimme->attachment->extension == ogg || $gimme->attachment->extension == mp4 || $gimme->attachment->extension == webm }}            
              {{assign var=multimediacurrent value=1}}
            {{ /if }} 
          {{ /list_article_attachments }}  
        {{ /if }} 
        {{* check now if multimedia found *}}
        {{if $multimediacurrent == 1}}
          {{* add to array with multimedia articles *}}
          {{append var=multimedia value="yes" index="`$gimme->article->number`"}}
          {{* increase counter to check for max number *}}
          {{ assign "multimediacounter" $multimediacounter+1 }}
        {{/if}}
      {{/if}}
    {{ /list_articles }} 

    {{* spit out what we found *}}
    {{$multimedia|@print_r}}
    {{* this is the resulting article list *}}
    {{foreach from=$multimedia key=articleID item=articleName}}
      {{ list_articles ignore_issue="true" ignore_section="true" length="1" constraints="number is `$articleID`"}}
        <li>Section:{{ $gimme->section->name }} | ID:{{$articleID}}: {{ $gimme->article->name }}</li>
      {{ /list_articles }}
    {{/foreach}}