• Resolved Peter Berger

    (@peterpolow)


    Hi Eliot,

    It’s me agian, with another question.

    I was trying to make a condition in an loop, that if the loop has just one result, the text “Announcement” will show before the first item, else “Announcements“.

    I thought it could be done with [if count=1], but I think that condition is only to check the number of the current item in the results, not the total results.

    Is there another way to check the total results of the loop?

    The code below is what I’m using now (without counting).

    [loop type=announcement field=expire after=now orderby=field_num order=ASC]
    [if first]
    	<aside class="widget">
    		<h3 class="widgettitle">Announcements</h3>
    		<div class="textwidget">
    			<ul>
    [/if]
    				<li>[content]</li>
    [if last]
    			</ul>
    		</div>
    	</aside>
    [/if]
    [if empty][/if]
    [/loop]

    Thank you in advance!

    Peter

    https://www.ads-software.com/plugins/custom-content-shortcode/

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

    (@miyarakira)

    With the latest update, you can use [if total] to check total post count. You could do something like:

    [if total=1]Announcement[else]Announcements[/if]
    Thread Starter Peter Berger

    (@peterpolow)

    Thanks you also for this nice solution!

    I just made another donation, to show my appreciation (not as compensation, because I think the spare-time you’re spending on it, is priceless).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Count total results in loop’ is closed to new replies.