0

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

1 Answer 1

0

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.

2
  • 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, 2011 at 13:40
  • yes, the first %s needed to be escaped, fixed it. Sep 18, 2011 at 13:41

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.