1

This code produces

Search Results for "hello" - 1 articles "

<h3>Search Results for <?php echo'"'?>
    <?php /* Search Count */ 
    $allsearch = &new WP_Query("s=$s&showposts=-1"); 
    $key = wp_specialchars($s, 1); 
    $count = $allsearch->post_count; 
    _e(''); 
    _e('<span class="search-terms">'); 
    echo $key; 
    _e('</span>'); 
    echo '"'; 
    _e(' - '); 
    echo $count . ' '; 
    _e('articles'); 
    wp_reset_query(); ?>
</h3>

How can I make it $single and $plural for eg. "1 article" or "2 articles"?

1
  • Found the answer replace if "_e('articles');" with "($count!=1) { _e(‘articles’); } else { _e(‘article’); }"
    – Josh
    Commented Mar 29, 2012 at 7:51

1 Answer 1

6

Instead of using 'if' loop it's better to use special function:

<?php echo _n( 'article', 'articles', $count, 'my-plugin-domain' ); ?>

http://codex.wordpress.org/Function_Reference/_n

5
  • +1 This is the proper way to do it. Unfortunately I don't think Poedit parses this correctly though. Commented Mar 29, 2012 at 8:12
  • @StephenHarris I can remember creating singular and plural translations in Poedit. Don't believe it should be a problem.
    – Geert
    Commented Mar 29, 2012 at 8:23
  • Thank you! Why do you have to use "$count, 'my-plugin-domain'"
    – Josh
    Commented Mar 29, 2012 at 8:36
  • 2
    @Josh The $count parameter is so the function knows which argument to use: singular or plural. The last parameter is the translation domain.
    – Geert
    Commented Mar 29, 2012 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.