• Resolved jbonlinea

    (@jbonlinea)


    Hi,

    Is it possible to add condition to the [IF][ELSE][/IF] or [EACH] template tag.
    If we take the example provided by pods here : https://docs.pods.io/displaying-pods/template-tags/example-template-tag-usage/

    books is a custom post type created with pods

    [before]<div class"book-wrap">[/before]
        [if books]
            <h5>Books</h5>
            <ul>
                [each books]
                <li>{@post_title}<li>
                [if cover_images]
                    <ul>
                        [each cover_images]
                        <li class"cover-image">{@_img.thumbnail}</li>
                        [/each]
                    </ul>
                [else]
                    <p class"no-images">No Images for this book</p>
                [/if]
                </li>
                [/each]
            </ul>
        [else]
            <p>Author has no books uploaded.</p>
        [/if]
    [after]</div><!--.book-wrap-->[/after]

    we can loop through our book. Great !
    However the loop display all the books, while some might still be draft or pending review, and not published yet !

    The stupid question is : is there a way to prevent the loop to display unpublished books

    The smarter one is : is there a way to set condition to select what the loop get

    In pseudo coded it could be something like :

    [if books where post-status="published"]

    or like
    [each books where post-status="published"]

    Cheers

    • This topic was modified 5 years ago by jbonlinea.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Jim True

    (@jimtrue)

    You would need to use PHP if you want that sort of action to take place.

    We do not support additional conditions on the [if] template tags or [each] template tags. The Pods Templates are not intended to replace PHP for that sort of functionality.

    Thread Starter jbonlinea

    (@jbonlinea)

    Ok, that’s lame, understandable, but lame, at least filtering only published post seems an obvious need !

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hello @jbonlinea

    If your field (books) allows unpublished books then these items showing in the loop is expected. If you don’t want unpublished items in the loop then make sure your field doesn’t allow such relationships.

    Cheers, Jory

    Thread Starter jbonlinea

    (@jbonlinea)

    Ohhh

    @keraweb I think I just got what you meant !
    That might be a good way to implement it in some case.
    Sticking with the example of pods site above, connectined to my use cas, It won’t work as I want the admin to be able to link a book with a an author through the custom field books while it’s not published yet, but I still don’t want it to be visible on the front end.

    Actually I think I found a way to deal with that through combining shortcode in template.

    Cheers

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hello @jbonlinea
    Check, that would not be possible with the provided [each] loops from Pods.

    Actually I think I found a way to deal with that through combining shortcode in template.

    That could be possible. Keep in mind that shortcodes within templates have it’s limitations. I’d recommend you use a separate template for the shortcode.

    Cheers, Jory

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[IF] or [EACH] templata tag with conditions’ is closed to new replies.