Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    There’s an [if] shortcode for simple conditionals (no post found, first/last post, every X posts). I can imagine some parameters could be added to further filter the loop.. Do you mean something like this?

    [loop type="post"]
        [content field="title"]
        [if in_category="cat1, cat5, cat7"]
            Display something
        [/if]
        [if taxonomy="status" has_term="discount"]
            On sale!
        [/if]
    [/loop]

    However, an inherent limitation of shortcodes is that they can’t be nested within itself, so [if] cannot be inside another [if].

    For complex queries, you may need to break it up into several loops, or write it in PHP – although it would be nice to find an elegant solution.

    Thread Starter psperkins

    (@psperkins)

    Yeah I was basically looking for a condition such is ‘in_category’ to show a call to action if the post in the loop has a specific category.

    I can do this easily in PHP but was just wondering if this could also be accomplished in a shortcode – I have found your plugin is especially useful in Genesis themes – I don’t use them all that often but when I do this plugin has become a go-to solution that is much simpler than creating multiple templates or loop functions.

    I hadn’t given any thought to nested ‘if’ statements in shortcodes so that’s useful new information for me.

    Thanks for your answer, I appreciate it.

    Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    I added a few parameters to the [if] shortcode to filter by category or taxonomy term. Please see the latest update.

    The parameters are used like this:

    [loop type="post"]
        [content field="title"]
        [if category="cat1, cat5, cat7"]
            Display something
        [/if]
        [if taxonomy="status" term="discount"]
            On sale!
        [/if]
        [if not taxonomy="status" term="discount"]
            Regular price
        [/if]
    [/loop]

    Hopefully that will add more flexibility to the loop. I appreciate the suggestion!

    Thread Starter psperkins

    (@psperkins)

    This works like a charm. Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using Conditional Statements’ is closed to new replies.