Walker_Comment::display_element()publicWP 2.7.0

Traverses elements to create list from elements.

This function is designed to enhance Walker::display_element() to display children of higher nesting levels than selected inline on the highest depth level displayed. This prevents them being orphaned at the end of the comment list.

Example: max_depth = 2, with 5 levels of nested content.

1
 1.1
   1.1.1
   1.1.1.1
   1.1.1.1.1
   1.1.2
   1.1.2.1
2
 2.2

Метод класса: Walker_Comment{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$Walker_Comment = new Walker_Comment();
$Walker_Comment->display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
$element(WP_Comment) (обязательный)
Comment data object.
$children_elements(массив) (обязательный) (передается по ссылке — &)
List of elements to continue traversing. Passed by reference.
$max_depth(int) (обязательный)
Max depth to traverse.
$depth(int) (обязательный)
Depth of the current element.
$args(массив) (обязательный)
An array of arguments.
$output(строка) (обязательный) (передается по ссылке — &)
Used to append additional content. Passed by reference.

Заметки

Список изменений

С версии 2.7.0 Введена.

Код Walker_Comment::display_element() WP 6.5.2

public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
	if ( ! $element ) {
		return;
	}

	$id_field = $this->db_fields['id'];
	$id       = $element->$id_field;

	parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );

	/*
	 * If at the max depth, and the current element still has children, loop over those
	 * and display them at this level. This is to prevent them being orphaned to the end
	 * of the list.
	 */
	if ( $max_depth <= $depth + 1 && isset( $children_elements[ $id ] ) ) {
		foreach ( $children_elements[ $id ] as $child ) {
			$this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
		}

		unset( $children_elements[ $id ] );
	}
}