Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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"?

share|improve this question
    
Found the answer replace if "_e('articles');" with "($count!=1) { _e(‘articles’); } else { _e(‘article’); }" –  Josh Mar 29 '12 at 7:51
add comment

1 Answer

up vote 5 down vote accepted

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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