Forum

Thread tagged as: Question, Problem

Filtering with perch_item_odd

I'm having an issue filtering using perch_item_odd. The field is in the template and if I don't suppress it gets output into the page (although it seems to get output on even items rather than odd), but when I try to use perch_content_custom to filter on it nothing shows on the page.

I'm pasting my template and page code below.

Template:

<a href="<perch:content id="galleryImg" type="image" width="900" quality="100" label="Gallery Image" required="true" />"><img src="<perch:content id="galleryImg" type="image" width="500" quality="70" />" alt="img <perch:content id="perch_item_odd" type="hidden" />"></a>

Page:

<section class="g-1-2">

        <?php
        perch_content_custom('Gallery', array(
            'filter'=>'perch_item_odd',
            'match'=>'eq',
            'value'=>'odd'
        ));
        ?>

    </section><section class="g-1-2">

        <?php
        perch_content_custom('Gallery', array(
            'filter'=>'perch_item_odd',
            'match'=>'neq',
            'value'=>'odd'
        ));
        ?>

</section>

If anyone else is having this problem and found a solution I'd appreciate the help. Thanks!

Chris Gerringer

Chris Gerringer 0 points

  • 7 years ago

Chris,

perch_item_odd

is ZERO indexed, which is why is displays... 0 (1) 2 (3) 4

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't filter on perch_item_odd. It's a templating feature, so it doesn't appear in the data - only when things are output by the template.

The next best thing would be not to filter, but to use a <perch:if exists="perch_item_odd"> in your template to only output every other item.

Thanks Drew, that should do the trick I think!