On this page
Walker_Comment::display_element( WP_Comment $element, array $children_elements, int $max_depth, int $depth, array $args, string $output )
Traverses elements to create list from elements.
Description
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
See also
Parameters
$elementWP_Comment Required-
Comment data object.
$children_elementsarray Required-
List of elements to continue traversing. Passed by reference.
$max_depthint Required-
Max depth to traverse.
$depthint Required-
Depth of the current element.
$argsarray Required-
An array of arguments.
$outputstring Required-
Used to append additional content. Passed by reference.
Source
File: wp-includes/class-walker-comment.php. View all references
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 ] );
}
}
Related
Uses
| Uses | Description |
|---|---|
| Walker::display_element() wp-includes/class-wp-walker.php | Traverses elements to create list from elements. |
| Walker_Comment::display_element() wp-includes/class-walker-comment.php | Traverses elements to create list from elements. |
Used By
| Used By | Description |
|---|---|
| Walker_Comment::display_element() wp-includes/class-walker-comment.php | Traverses elements to create list from elements. |
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/walker_comment/display_element