[wp-trac] [WordPress Trac] #12223: Adding a titles to comment levels with the walker class

WordPress Trac wp-trac at lists.automattic.com
Sun Feb 14 11:20:07 UTC 2010


#12223: Adding a titles to comment levels with the walker class
--------------------------+-------------------------------------------------
 Reporter:  danielpataki  |       Owner:                                
     Type:  enhancement   |      Status:  new                           
 Priority:  normal        |   Milestone:  Unassigned                    
Component:  Comments      |     Version:                                
 Severity:  normal        |    Keywords:  walker class, wp_list_comments
--------------------------+-------------------------------------------------
 Hi Everyone!

 This is only my second post here, and my first feature request, so please
 excuse me if I have duplicated something or my solution is completely
 unsuitable.

 I am experimenting with the CMS capabilities of Wordpress, especially the
 enhanced post_type GUI in the new 3.0 alpha release. While building a sort
 of Yahoo Answers type platform, I wanted to have 1st level comments as
 answers to a question (a post), and 2nd level comments as comments on the
 answer (1st level comments). I wanted to label comments on an answer as
 "comments", but this is not really possible to do, to my knowledge, using
 "wp_list_comments".

 I created my own function for wp_list_comments so I didn't have to modify
 Wordpress core, in order to get at the walker class at the bottom of
 wp_list_comments. I wanted to use start_lvl to add a title for comment
 level 2. However, start_lvl in "class Walker_Comment extends Walker" will
 only let you change the list type to "ul", "ol" or "div". My idea is to
 add an argument which would allow you to add a title, along with
 specifying it's heading (or surrounding tag). As I said, I am not an
 expert on Wordpress coding standards, so the following code may be
 completely off.

 {{{
 /**
    * @see Walker::start_lvl()
    * @since unknown
    *
    * @param string $output Passed by reference. Used to append additional
 content.
    * @param int $depth Depth of comment.
    * @param array $args Uses 'style' argument for type of HTML list.
    * @param array $args Uses 'title' argument for title text.
    * @param array $args Uses 'title_heading' argument for title text
 heading level.
    */


 function start_lvl(&$output, $depth, $args) {
   $GLOBALS['comment_depth'] = $depth + 1;

     switch ( $args['style'] ) {
       case 'div':
         break;
       case 'ol':
         echo "<ol class='children'>\n";
         break;
      default:
      case 'ul':
         echo "<ul class='children'>\n";
         break;
     }

         if (!empty ($args['title'])) {

       if(!empty ($args['title_heading'])) {
             echo '<'.$args['title_heading'].'>';
           }

           echo $args['title'];

           if(!empty ($args['title_heading'])) {
             echo '</'.$args['title_heading'].'>';
           }

         }

 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12223>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list