Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Maybe I am missing something, but I really cant figure out why the zebra tag isn't working for me. This is my code:

Code: Select all
                    <cms:query sql="  SELECT p.id pid, t.name tname
        FROM <cms:php>echo K_TBL_PAGES;</cms:php> p
        inner join <cms:php>echo K_TBL_TEMPLATES;</cms:php> t
        on p.template_id = t.id
        WHERE (t.name='artikkel.php' or t.name='anmeldelse.php' or t.name='video.php')
        AND publish_date < '<cms:date format='Y-m-d H:i:s' />'
        AND NOT publish_date = '0000-00-00 00:00:00'
        ORDER BY publish_date desc;" limit='4' offset='1'>

                        <cms:pages masterpage=tname id=pid>

                            <div class="<cms:zebra 'article_left' 'article_right' />">
                                <div class="article_image_normal">
                                    <a href="<cms:show k_page_link />" class="imglink">
                                        <img src="<cms:if k_template_name='artikkel.php' ><cms:show artikkel_bilde /></cms:if><cms:if k_template_name='anmeldelse.php' ><cms:show anmeldelse_bilde /></cms:if>" class="imglink">
                                    </a>
                                </div>
                                <p>
                                    <cms:if k_template_name='anmeldelse.php'>Anmeldelse</cms:if>
                                    <cms:if k_template_name='artikkel.php'>Artikkel</cms:if>
                                    <cms:if k_template_name='video.php'>Video</cms:if> / <a href="<cms:show k_site_link /><cms:if k_template_name='anmeldelse.php' >anmeldelse/</cms:if><cms:if k_template_name='artikkel.php' >artikkel/</cms:if><cms:show k_page_foldername />">
                                        <cms:show k_page_foldertitle /></a>
                                </p>
                                <h3><a href="<cms:show k_page_link />">
                                        <cms:show k_page_title /></a></h3>
                                <p>
                                    <cms:excerpt count='150' truncate_chars='1'>
                                        <cms:if k_template_name='artikkel.php'>
                                            <cms:show artikkel_korttekst />
                                        </cms:if>
                                        <cms:if k_template_name='anmeldelse.php'>
                                            <cms:show anmeldelse_korttekst />
                                        </cms:if>
                                    </cms:excerpt>
                                </p>
                            </div>
                        </cms:pages>
                    </cms:query>


Sorry about the long code. But shouldn't the zebra tag work here? To alternate between the div classes? All it does is add the article_left class to all the divs.
Zebra won't work there because cms:pages runs only once - for each fetched pid, so there is no loop.

Tag cms:query has a parameter fetch_pages='1', so extra cms:pages tag can be avoided. This param requires id and template_id present among the columns. Zebra will work if you modify your code that way, because cms:query will loop several times (4 in your case).

Alternative solution is to move cms:zebra outside of cms:pages and save its output into some variable to use within the inner loop -
Code: Select all
<cms:set my_class="<cms:zebra 'left' 'right' />" />
trendoman wrote: Could you please check the output of a simplified code -
Code: Select all
<cms:query sql=my_sql>

    <cms:pages masterpage=tname id=pid>
        <cms:show k_current_record />: <cms:zebra 'article_left' 'article_right' />
    </cms:pages>   

</cms:query>


On a side note, cms:query has a parameter fetch_pages='1', so extra cms:pages tag can be avoided. This param requires id and template_id present among the columns.


Hi,
That code outputs this:
Code: Select all
1: article_left 1: article_left 1: article_left 1: article_left
I have corrected my post :)
Please see if it helps.

P.S. You can see in the output of simplified code that k_current_record always returns '1' - this is a hint that there is no loop.
trendoman wrote: Zebra won't work there because cms:pages runs only once - for each fetched pid, so there is no loop.

Tag cms:query has a parameter fetch_pages='1', so extra cms:pages tag can be avoided. This param requires id and template_id present among the columns. Zebra will work if you modify your code that way, because cms:query will loop several times (4 in your case).

Alternative solution is to move cms:zebra outside of cms:pages and save its output into some variable to use within the inner loop -
Code: Select all
<cms:set my_class="<cms:zebra 'left' 'right' />" />


Sweet, I got it to work using cms:set.

I can't find any information about cms:query in the documentation, so that template-id stuff was too advanced for me, hehe.

Thanks for the help!
You are welcome.

For reference, the code below is the supposed change -

<cms:query sql=" SELECT p.id, t.template_id
FROM <cms:php>echo K_TBL_PAGES;</cms:php> p
inner join <cms:php>echo K_TBL_TEMPLATES;</cms:php> t
on p.template_id = t.id
WHERE (t.name='artikkel.php' or t.name='anmeldelse.php' or t.name='video.php')
AND publish_date < '<cms:date format='Y-m-d H:i:s' />'
AND NOT publish_date = '0000-00-00 00:00:00'
ORDER BY publish_date desc;" limit='4' offset='1' fetch_pages='1'>

<div class="<cms:zebra 'article_left' 'article_right' />">
...
</div>

</cms:query>
6 posts Page 1 of 1