ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Dynamic control of singular or plural (PHP conditionals?)

March 15, 2011 2:54pm

Subscribe [2]
  • #1 / Mar 15, 2011 2:54pm

    Evolve Websites

    110 posts

    Hi there,

    I would like create a command to turn ‘1 Search Results’ (plural) into ‘1 Search Result’ (singular). Obviously if more than one result is created, I’d like to keep the plural version.

    I believe this is a common PHP conditional, but I have very little experience of PHP.

    My code looks like this:

    <h2><em>{exp:search:total_results}{total}{/exp:search:total_results} search results for</em> “{exp:search:keywords}”</h2>

    Any help is appreciated!

  • #2 / Mar 15, 2011 3:26pm

    Mark Bowen

    12637 posts

    Totally untested but see if this works?

    <h2><em>{exp:search:total_results}{total_results}{/exp:search:total_results} search result{if "{exp:search:total_results}" != 1}s{/if} for</em> “{exp:search:keywords}”</h2>

    I’m in a rush out so if that doesn’t work let me know and I’ll take another look. There might be a better way of doing this too so pardon me if there is but as mentioned I’m in a rush 😉

    Best wishes,

    Mark

  • #3 / Mar 16, 2011 1:47pm

    Evolve Websites

    110 posts

    Bang on, I’m impressed.

    Thanks Mark!

  • #4 / Mar 16, 2011 2:19pm

    Mark Bowen

    12637 posts

    Hi Tom,

    No problem at all. Seems my memory served me well for something after all 😉

    Glad that’s got it sorted for you.

    Best wishes,

    Mark

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases