Support

Account

Home Forums Add-ons Repeater Field Pluralize title if more than one image exists

Solving

Pluralize title if more than one image exists

  • Each contestant has their own page on the website where the image(s) of their sponsor(s) are displayed. If there are two or more images it should say “Sponsors:”, if one image than “Sponsor:”, and if no image than null. The following code works for the first two but the last one still shows “Sponsor:” even when no image has been entered in the repeater field. NOTE: The first line “echo count” I’m using to see what number is being calculated for each post and it is showing “1” when there are no images in the repeater.

    <?php
    echo count( get_field('sponsors') );
    if( have_rows('sponsors') ):
      $my_fields = get_field_object('sponsors');
      $count = (count($my_fields['value']));
     endif;
      echo "<h3>";
      if ( $count > 1 ) { ;
      echo "Sponsors:</h3><div class='clear'></div>";
      } elseif ( $count = 1 ) { ;
      echo "Sponsor:</h3><div class='clear'></div>";
      } elseif ( $count < 1 ) { ;
      echo "</h3><div class='clear'></div>";
      } ;
    ?>

    I’ve also tried doing separate if statements instead of using the elseif but that had no effect.

    Any suggestions on what is going on with this?

  • // only 1 = needs to be 2 ==
    } elseif ( $count == 1 ) {
  • lol. My bad. Sometimes you just overlook the obvious. Thank you!

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

The topic ‘Pluralize title if more than one image exists’ is closed to new replies.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.