Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#9301 closed defect (bug) (fixed)

no classes on div-coment in Walker_Comment::start_el()

Reported by: docwhat Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.7
Component: Template Keywords: has-patch tested
Focuses: Cc:


There are no classes on Walker_Comment::start_el() when it creates a <div id="div-comment-NNNN"> node.

This makes using CSS target that node pretty hard if not impossible across browsers.

Ideally, it would have a class like "comment-body".

This is a feature aid semantic markup.

Change History (6)

comment:1 docwhat5 years ago

Example Patch

diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php
index a4a126b..49cdfc1 100644
--- a/wp-includes/comment-template.php
+++ b/wp-includes/comment-template.php
@@ -1221,3 +1221,3 @@ class Walker_Comment extends Walker {
                <?php if ( 'ul' == $args['style'] ) : ?>
-               <div id="div-comment-<?php comment_ID() ?>">
+               <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
                <?php endif; ?>

comment:2 docwhat5 years ago

  • Keywords has-patch added

comment:3 Viper007Bond5 years ago

Wouldn't using the parent element which has comment_class() on it work?

comment:4 docwhat5 years ago

It would have before we added the "Reply" and nested comments. But now the markup can change, on the fly, from (this is from memory, so the classes might be wrong):

<li class="comment">
  <div id="div-comment-NN" />


<li class="comment">
  <div id="div-comment-NN" />
  <div id="response" />

So you can't use a rule like:

.comment > div { ... style the body of the comment ... }

... without getting the reply box, too.

Before this change, I'd just use css like this:

.comment { border: 1px solid blue; }

But the box will bound the replies too; which isn't what I wanted.


comment:5 Denis-de-Bernardy5 years ago

  • Component changed from General to Template
  • Keywords tested added
  • Milestone changed from Unassigned to 2.8
  • Version set to 2.7

comment:6 ryan5 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [10961]) Add comment-body class. Props docwhat. fixes #9301

Note: See TracTickets for help on using tickets.