• Resolved nyoz

    (@nyoz)


    Hi again !

    I’m continuing my wonderful uses of your plugin, and it’s still as awesome ! πŸ™‚

    I had a quick question though : is there a way to get the incrementation index of the loop ?
    What I mean by that is that I want to put some code of a field value only on the modulo 3 outputs of the loop (so every 3 results). The final purpose is to generate a row every 3 items.

    Is it possible with an [if something] ? Or is it related to the pagination query (http://ww.wp.xz.cn/support/topic/pagination-133)

    Cheers !
    Regards,
    – nyoz

    https://ww.wp.xz.cn/plugins/custom-content-shortcode/

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

    (@miyarakira)

    Hello,

    I added a few parameters to the [if] shortcode to achieve what you described. Please see the latest update.

    To display something on every 3 results:

    [loop type="post"]
        [content field="title"]
        [if every="3"]
            <hr>
        [/if]
    [/loop]

    In addition, there’s [if first] and [if last] to display something on the first or last post.

    Hopefully these can be combined to do what you wanted. As I was testing these, I realized it’s not so simple to add opening and closing tags around 3 posts at a time, if the total number of posts is not divisible by 3.

    So, please let me know if it works for you.

    As for the pagination add-on, it’s taken me longer than planned, but I’m working on it. πŸ™‚

    Thread Starter nyoz

    (@nyoz)

    Works like a charm ! I’m adding a <div class=”clearfix”></div> every 3 items, and the global container is declared outside the loop, so there’s no issue if the total isn’t %3.

    Thanks again for your reactivity, amazing ! πŸ™‚

    Plugin Author Eliot Akira

    (@miyarakira)

    Perfect, I’m glad it worked for your purpose.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Getting the loop incrementation index (-> if %3)’ is closed to new replies.