• Hey Everyone, 2.7 is pretty sweet so far, just ran into a small problem.

    I’ve used this handy guide to get better control over styling my comments. https://clarktech.no-ip.com/wordpress/wordpress-27-comment-callback-function

    I want to implement a comment count (1, 2, 3, 4, etc) for each new comment that will be displayed next to it. I’ve used these functions that have worked for me before:

    Before the loop
    <?php $cmntCnt = 1; ?>

    Within the loop
    <?php echo($cmntCnt++); ?>

    Now that my comment styling is in a function, they don’t seem to work anymore. They only output “1” for each comment.

    Any ideas?
    Hope that made sense.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Anybody can solve this problem? I need this too

    thanks

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    This worked for me (PHP programmers please comment, my PHP fu can be lacking).

    In your function.php define $cmntCnt as global

    <?php
    function custom_comment($comment, $args, $depth) {
           $GLOBALS['comment'] = $comment; ?>
           <?php global $cmntCnt; ?>

    Then output the $cmntCnt in the function where/how you want it

    <?php echo $cmntCnt+1; ?>

    And at the bottom before the end of the function, increment the comment count

    <?php $cmntCnt = $cmntCnt + 1; ?>
    <?php } ?>

    See if that works for you. I’m still playing with the styling of mine, but this validates on my blog and PHP is not tossing errors.

    Happy New Year.

    Thanks you it’s work now

    It’s work for me also. Thanks for Sharing

    After hours of seraching, finally I’ve found this solution, thanks alot

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Comments Count in 2.7’ is closed to new replies.