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

    (@miyarakira)

    It’s a bit tricky..

    To list tags with links to pass the selected tag as a query variable:

    [for each=tag count=10 trim=true]
      <a href="?tag=[each slug]">[each name]</a>,
    [/for]

    Then, on the same page, to list posts with the passed tag..

    [pass global=query fields=tag]
    [loop type=post tag={TAG}]
      [field title] - [taxonomy tag]
    [/loop]
    [/pass]

    The above with list all posts if no tag is selected. To check if any tag was passed:

    [if pass={TAG} empty=false]
      ..loop..
    [else]
      No tag selected
    [/if]

    To display the term label, inside the [pass] block:

    [for each=tag term={TAG}]Selected tag: [each name][/for]
    Thread Starter flodi

    (@flodi)

    As usual your support is stellar!

    Everything works but the IF to check if no tag is selected.

    I have this code:

    [for each=tag]
        <div class="onetag"><a href="?tag=[each slug]">[each name]</a></div>
    [/for]
    <div>
    [pass global=query fields=tag]
        [loop type=page fields=url,titolo parent=340 exclude=360 tag={TAG}]
            <a href="{URL}">
            <div class="mitem">
                <div>{TITOLO}
                    <div><img src="/wp-content/uploads/2015/11/ricetta-hat.png">[if not field="difficolta" value="1"]<img src="/wp-content/uploads/2015/11/ricetta-hat.png">[/if][if field="difficolta" value="3"]<img  src="/wp-content/uploads/2015/11/ricetta-hat.png">[/if]</div>
                </div>
                <div>[field image]</div>
                <div>[for each=tag]<div>[each name]</div>[/for]</div>
                <div>[ratings] [os_share]</div>
            </div>
            </a>
        [/loop]
    [/pass]
    </div>

    That works, but does not contains an IF, as you can see because if I try, everything seems going bad.

    I want to show everything in case no tag is selected. If I leave the code as is, and tag is empty, it will get everything?

    Thread Starter flodi

    (@flodi)

    Resolved by myself, it worked selecting all if tag empty.

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

The topic ‘Filter in Loop?’ is closed to new replies.