Make WordPress Core

Opened 17 years ago

Closed 13 years ago

Last modified 13 years ago

#12223 closed feature request (invalid)

Adding a titles to comment levels with the walker class

Reported by: danielpataki Owned by:
Priority: normal Milestone:
Component: Comments Version:
Severity: normal Keywords:
Cc: Focuses:

Description

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'].'>';
	  }
	
	}
	
}

Change History (5)

#1 @nacin
17 years ago

You can provide wp_list_comments() with a callback. You can also extend the existing walker if you need that kind of control.

#2 @janeforshort
17 years ago

  • Milestone UnassignedFuture Release
  • Type enhancementfeature request

#3 follow-up: @danielpataki
17 years ago

Yes, I normally use a callback to format everything, but while this allows me to format any comment, I cant do anything before the 2nd level comments start for a first level.

I just got into objects in PHP a month or so, and I don't have the expertise to do that quickly for myself, so I will probably just use a custom query to list all the comments I need, and their sub-comments, adding a title before the 2nd level ones.

It would however be an option which would feel very "wordpress"-like, to enable comment level titles with a "title_li", perhaps in the wp_list_comments itself. This would be a little more difficult since you can have many levels, so maybe an array would be best?

Anyway, thanks for helping out. I will try and submit better tickets, please do tell me if I am being over-helpful here.

#4 in reply to: ↑ 3 @westonruter
13 years ago

  • Keywords close added
  • Resolutioninvalid
  • Status newclosed

Replying to danielpataki:

Yes, I normally use a callback to format everything, but while this allows me to format any comment, I cant do anything before the 2nd level comments start for a first level.

The wp_list_comments callback argument actually does get called for all comments on all thread depth levels, not just the first level. Also take note of the end-callback argument as well: http://codex.wordpress.org/Function_Reference/wp_list_comments

#5 @helen
13 years ago

  • Keywords walker class wp_list_comments close removed
  • Milestone Future Release
Note: See TracTickets for help on using tickets.