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.

Looking to replace static string text in this function with dynamic text from a var.

Current model:

  comments_number( 'no responses', '1 response', '% responses' );

Ideal Outcome (code guess):

  comments_number( '$no_responce_text', '1'.$responce_text, '%'.$responce_text );

I am sure this is an easy php question but stumped here.

Any help would be nice.

Thanks

share|improve this question

1 Answer 1

up vote 0 down vote accepted

This should do it:

comments_number(
   $no_responce_text,
   sprintf('1 %s', $responce_text), 
   sprintf('%% %s', $responce_text)
);`

Use get_comments_number if you want it properly localized.

share|improve this answer
    
There is one issue is with the last part, it is only outputting 2s (2 being a number greater than 1). Any thoughts on how to output the text with it? Does it have to do with the two %? –  estern23 Sep 18 '11 at 13:40
    
yes, the first %s needed to be escaped, fixed it. –  onetrickpony Sep 18 '11 at 13:41
    
Perfect! that did the trick! thanks for the help –  estern23 Sep 18 '11 at 13:42

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.