0

I am needing to obtain a count for every video being parsed through Channel Videos via relationship entries. I want to continue using a grid with my layout so the content can scale like the rest of the site.

I have a channel of entries which is nothing more than a DevDemon Channel Entries field which contains groups of videos. Each of these groups can be added to other channel entries as modules. So you may have a Lesson Module with 5 groups of videos and each video group could have 1-?? videos in it.

I was using an embed for the relationship loop, but I was loosing count each time and starting over at 0/1, so I started trying to calculate the numbers via raw PHP. I am completely open as a better way of doing this because I am banging my head against the desk. lol

Here was my latest attempt:

<ul class="classes available-classes clearfix"> 
    <?php $count = 0; ?>
    {exp:channel:entries 
        disable="category_fields|member_data|pagination" 
        category="1" 
        channel="program_module" 
        status="open" 
        show_future_entries="no" 
        show_expired="no" 
    }
        {video_groups_to_include}
            {exp:channel_videos:videos 
                status="open" 
                entry_id="{video_groups_to_include:entry_id}" 
            }
                <?php 
                    $count++;
                    echo $count;
                    if( $count==1 || $count==5 || $count==9 || $count==13 || $count==17 || $count==21 || $count==25 || $count=29 || $count==33 || $count==37 || $count==41 || $count==45 || $count=49 || $count==53 || $count==57 || $count==61 || $count==65 || $count==69 ){
                        echo "<li class='row-fluid'><ul><li data-id='id-{video:id}' class='span3 {video_groups_to_include:categories}{category_name}{/video_groups_to_include:categories}'>";
                    }else{
                        echo "<li data-id='id-{video:id}' class='span3 {video_groups_to_include:categories}{category_name}{/video_groups_to_include:categories}'>";
                    }
                ?>
                    <a href="{site_url}lessons/{video_groups_to_include:categories}{category_url_title}{/video_groups_to_include:categories}">
                        <em class="overflow-hidden"><img src="{video:img_url_hd}" alt="{video:title}" /></em>
                        <span>
                            <strong>{video:title}</strong>
                            <i>{video:description}</i>
                        </span>
                    </a>
                <?php 
                    $count++;
                    if( $count==4 || $count==8 || $count==12 || $count==16 || $count==20 || $count==24 || $count==28 || $count=32 || $count==36 || $count==40 || $count==44 || $count==48 || $count=52 || $count==56 || $count==60 || $count==64 || $count==68 || $count==72 ){
                        echo "</li><ul></li>";
                    }else{
                        echo "</li>";
                    }
                ?>
                </li>
            {/exp:channel_videos:videos}
        {/video_groups_to_include}
    {/exp:channel:entries}
</ul>

Hopefully it's clear what I am trying to achieve. Basically, I need a new row after ever 4th video parsed. (4 column layout)

0

You can easily do this with the switch variable. Have a look at my answer on this posting. The answer refers to matrix, but really it should be applicable in any looping tag pair that support the switch variable, and I think, though it's not mentioned in the documentation, it should be supported in Channel Videos.

| improve this answer | |
  • Hey Jean. Thanks for the suggestion. I read through your other answer and have given this much thought. The problem I see with this approach is as follows. This is actually a nested looping statement, or complex loop. The entry is processing the relationships. Therefor the entries selected as relationships is the outer loop. In this first example, that is '4'. Each one of the related entries then has a Channel Videos field consisting of multiple videos. – W3bGuy Apr 21 '14 at 1:08
  • In this case, the 4 entries have the following respectively. 1) 2, 2) 5, 3) 1, and entry 4) 3. So all in all, I will be displaying 11 videos. this would give me a total of 3 rows of 4 columns with the 3rd row being empty in the last field. Using 'Switch' sounds good, but Am I wrong in assuming that it would only process either the outer loop, inner loop, or both, but only individually? I need it to keep a continuous count of all videos being rendered. This is why I was trying to process it with PHP. With the PHP, I keep running into parsing issues though. – W3bGuy Apr 21 '14 at 1:10
0

Ok, so for this one, I might have been able to use stash to store the videos and then dump them out, but I felt it was easier to just enable PHP on output for this template and use the following:

<?php $counter = 0; ?>
<ul class="portfolio recent-work clearfix">
    <li>
        <ul class="row-fluid">
            {exp:channel:entries 
                disable="category_fields|member_data|pagination" 
                category="1" 
                channel="program_module" 
                status="open" 
                show_future_entries="no" 
                show_expired="no" 
            }
                {video_groups_to_include}
                    {exp:channel_videos:videos 
                        status="open" 
                        entry_id="{video_groups_to_include:entry_id}" 
                    }
                        <?php $counter++; ?>
                        <li data-id='id-{video:id}' class='span3 {video_groups_to_include:categories}{category_name}{/video_groups_to_include:categories}' style="margin-right: 0;">
                            <a href="">
                                <em class="overflow-hidden"><img src="{video:img_url_hd}" alt="{video:title}" style="width: 100%;" /></em>
                                <span>
                                    <strong>{video:title}</strong>
                                    <i>{video:description}</i>
                                </span>
                            </a>
                        <?php if (($counter % 4) == 0) { echo "</li></ul><ul class='row-fluid'>"; } else { echo "</li>"; } ?>
                    {/exp:channel_videos:videos}
                {/video_groups_to_include}
            {/exp:channel:entries}
        </ul>
    </li>
</ul>

Hopefully this helps someone down the road...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.