Comment counts: Manually add + (some number) to the count (3 posts)

  1. gnarayan
    Posted 1 year ago #

    Okay got a TOUGH one for you guys:

    Have this:

    <?php comments_popup_link('0','1','%', ' ', '-'); ?>

    But I'm trying to do this

    <?php comments_popup_link('0','1','%+5', ' ', '-'); ?>

    (obviously this does not work but renders something like 32+5 instead of 37)

    I know this CAN be done, just don't know how...

    Thank yew!

  2. bcworkz
    Posted 1 year ago #

    It CANNOT be done as something you pass to the function. The argument parsing is simply not very sophisticated. But you are right, it's possible to alter the count.

    To make the process easier, just pass the '%' with no text as you first illustrated, even if you do want additional text. (it actually doesn't matter what you pass, the % alone reflects what's happening conceptually) Hook the 'comments_number' filter. Your callback is passed the comment count as the second parameter in the form of an honest integer. Ignore the first parameter, it's the same number as a string.

    Do whatever math you want with the comment count integer, then if you like, concatenate any string you like to the result and return the whole thing, something like this: return ( $int + 5 ) . ' ruminations';.

  3. gnarayan
    Posted 1 year ago #

    Thanks a mil. Gonna have to tackle this after work because it looks complicated...

Topic Closed

This topic has been closed to new replies.

About this Topic