WordPress.org

Ready to get started?Download WordPress

Forums

Create incremental number for each comment per art (22 posts)

  1. chiensavant
    Member
    Posted 9 years ago #

    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. :)

  2. Mark (podz)
    Support Maven
    Posted 9 years ago #

      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 ?

  3. Root
    Member
    Posted 9 years ago #

    Well I rather had my eye on that myself ;)

  4. chiensavant
    Member
    Posted 9 years ago #

    Humm... I presume you will share you solution, won't you ? :p

  5. Root
    Member
    Posted 9 years ago #

    Well I will when I work out how its done ;)

  6. chiensavant
    Member
    Posted 9 years ago #

    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.

  7. Root
    Member
    Posted 9 years ago #

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

  8. Root
    Member
    Posted 9 years ago #

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

  9. Root
    Member
    Posted 9 years ago #

    @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.

  10. chiensavant
    Member
    Posted 9 years ago #

    @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...

  11. chiensavant
    Member
    Posted 9 years ago #

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

  12. Root
    Member
    Posted 9 years ago #

    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.

  13. Anonymous
    Unregistered
    Posted 9 years ago #

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

  14. Root
    Member
    Posted 9 years ago #

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

  15. chiensavant
    Member
    Posted 9 years ago #

    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.

  16. Root
    Member
    Posted 9 years ago #

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

  17. chiensavant
    Member
    Posted 9 years ago #

    That is certainly something that I would love to see working. But so far it is not supported by any browser.
    So I'm still looking for a better solution. I'm looking into a SQL oriented solution at this time...

  18. Stevarino
    Member
    Posted 9 years ago #

    Why not try this... Enter /wp-comments.php and change this section:
    foreach ($comments as $comment)
    To this:
    foreach ($comments as $comment_id => $comment)
    Then anywhere in that loop you just have to call something like:
    <?php echo $comment_id++; ?>. I'm sure if you wanted more control a plugin could enhance this, but it should work for now...
    Try this:
    <div class="commentnumber"><php echo $comment_id++;?></div>

  19. Anonymous
    Unregistered
    Posted 9 years ago #

    Stevarino, I just tried using your code, but found that the numbers started at 0 instead of 1 - I added this:

    $comment_id += 1;

    Just before the echo line, which fixed it - there's almost certainly a cleverer way of dealing with it though.

  20. ZBRob
    Member
    Posted 9 years ago #

    Heh... I hope so. I see so many blogs that edit the way the comments are numbered (http://photomatt.net and http://www.jinabolton.com to name only two), but I just can't get it done in a nice way. I'll try Stevarino's way, and I'll let you know...

  21. ZBRob
    Member
    Posted 9 years ago #

    Well, thanks Stevarino! That works. Now I can style away :op

  22. GrendelS
    Member
    Posted 8 years ago #

    Starvino's way is a hack that gets overwritten every time WP is updated - is there another way to assign numbers to comments?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.