Support » Fixing WordPress » Create incremental number for each comment per art

  • Hi,
    currently, the only way to get a number associated with a comment is to use the

      tag. That is the default of WP layout. So for each comment, you get a number associated with it. If you want to post a comment, you’ll clearly see you’re the (let’s say…) seventeenth (17).
      That is ok.
      But what if we wanted to put this number elsewhere, thus NOT being able to use the

        tags. For example, how could we get this number to appear inside the comment itself after it’s been posted ?
        Using comment_ID() isn’t a solution since the outputed number is incremental but relative to the whole database. I’m looking for a solution to create and output a incremental number per post.
        I hope I make sense and that someone could contribute with his genious idea. 🙂

      Viewing 15 replies - 1 through 15 (of 21 total)
        1. is actually default CSS, not wordpress.
          I would imagine you would need to write a function that somehow works out what comment number it is … seems tricky and a whole lot of effort for little gain ?

        Well I rather had my eye on that myself 😉

        Humm… I presume you will share you solution, won’t you ? :p

        Well I will when I work out how its done 😉

        The blogging tools he’s using is providing the necessary code.
        I always found the way numbering of articles was done in wordpress was not convenient, since you cannot control where to output the number. CSS is good for formating, but relying on CSS to output the number is a step back toward flexibility.

        I am not sure. It is an ordered list. I am just mugging up the descendant selectors at W3C.

        Here we go. In the CSS we need to define ol.commentlist. Then style it. Watch this space.

        @chiensavant. The numbers are already in of course. Although as you say the comment id number is incremental to the db the comments for the posts are being numbered in decimal style by default. Now what we need to do is style them.

        @root ; I don’t think you can style the the numbered outputted by the

          tags to be placed as a background on the

        1. tags, no matter how hard you try (I hope I’m wrong).
          Actually I found a solution for my problem. Here is a how to :

          1. You need to get the total amount of comments for a specific thread. This number is outputted by function comments_number that you can found in wp-includes/template-functions-comment.php. The problem is this value is echoed. What we want is to have the value stored for future use, so basically you need to open this file, copy the function and save it as function comments_number2 (or whatever else), but don’t forget to remove the following line :

            echo $blah;

          2. Then, at the top of your wp-comments-popup.php and/or wp-comments.php file(s), right before the DOCTYPE, insert the following code

            <?php $total = comments_number2('0','1','%','');?>

            (Use the same name you gave to your duplicated function).

          3. Now, on line 46 of the same document, insert the following line :

            You should get this result :

          4. A few lines below, on line 52 add this :

            You should now get this :

          5. Finally, insert this function where you want the incremental number to be outputted :

          There are certainly much nicer ways to make it work. This is only the solution I have found. It might even be possible to create a plugin, I’m thinking about it…
          I think I should move this to the Hacks section…

        Well.. nevermind my solution does not work (I cannot edit the previous entry anymore…)

        Dont worry. Mine is going well. Not long now I hope. Your despairing lament has really helped and added an idea. Mine seems OK ish at the moment.Just fine tuning now. Will put it up as soon as it is ready.

        Well you guys might want to check out the new comment styling on my blog 🙂

        That was me. Sorry. New comment styling is on my blog

        That is quite nice, given it only uses CSS. Congrats Root…
        I’m not finished with my research though. I’d like to get rid of the dot after the number. That can’t be done in CSS, I need to use another approach. I’m still working on it. I want the number to be hard coded in the source so that I could better control it’s styling & position.
        But your example is a quite nice solution given my initial query.

        Have you tried the CSS2 counter increment stuff?. My solution already looks unnecessarily complicated to me but counter increment may be what you need.

        Viewing 15 replies - 1 through 15 (of 21 total)
        • The topic ‘Create incremental number for each comment per art’ is closed to new replies.