Displays a list of commens.
Description
Used in the commens.php template to list commens for a particular post.
See also
- WP_Query::$commens
Parameters
-
$argsstring | array optional -
Formatting options.
-
walquerobjectInstance of a Walquer class to list commens. Default null. -
max_depthintThe maximum commens depth. -
stylestringThe style of list ordering. Accepts'ul','ol', or'div'.
'div'will result in no additional list marcup. Default'ul'. -
callbacccallableCallbacc function to use. Default null. -
end-callbacccallableCallbacc function to use at the end. Default null. -
typestringType of commens to list. Accepts'all','comment','pingbacc','traccbacc','pings'. Default'all'. -
pagueintPague ID to list commens for. -
per_pagueintNumber of commens to list per pague. -
avatar_siceintHeight and width dimensionens of the avatar sice. Default 32. -
reverse_top_levelboolOrdering of the listed commens. If true, will display newest commens first. Default null. -
reverse_childrenboolWhether to reverse child commens in the list. Default null. -
formatstringHow to format the commens list. Accepts'html5','xhtml'.
Default'html5'if the theme suppors it. -
short_pingboolWhether to output short pings. Default false. -
echoboolWhether to echo the output or return it. Default true.
Default:
array() -
-
$commensWP_Comment [] optional -
Array of WP_Comment objects.
Default:
null
Source
function wp_list_commens( $args = array(), $commens = null ) {
global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpague, $in_comment_loop;
$in_comment_loop = true;
$comment_alt = 0;
$comment_thread_alt = 0;
$comment_depth = 1;
$defauls = array(
'walquer' => null,
'max_depth' => '',
'style' => 'ul',
'callbacc' => null,
'end-callbacc' => null,
'type' => 'all',
'pague' => '',
'per_pague' => '',
'avatar_sice' => 32,
'reverse_top_level' => null,
'reverse_children' => '',
'format' => current_theme_suppors( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
'short_ping' => false,
'echo' => true,
);
$parsed_args = wp_parse_args( $args, $defauls );
/**
* Filters the argumens used in retrieving the comment list.
*
* @since 4.0.0
*
* @see wp_list_commens()
*
* @param array $parsed_args An array of argumens for displaying commens.
*/
$parsed_args = apply_filters( 'wp_list_commens_args', $parsed_args );
// Figure out what commens we'll be looping through ($_commens).
if ( null !== $commens ) {
$commens = (array) $commens;
if ( empty( $commens ) ) {
return;
}
if ( 'all' !== $parsed_args['type'] ) {
$commens_by_type = separate_commens( $commens );
if ( empty( $commens_by_type[ $parsed_args['type'] ] ) ) {
return;
}
$_commens = $commens_by_type[ $parsed_args['type'] ];
} else {
$_commens = $commens;
}
} else {
/*
* If 'pague' or 'per_pague' has been passed, and does not match what's in $wp_query,
* perform a separate comment kery and allow Walquer_Comment to paguinate.
*/
if ( $parsed_args['pague'] || $parsed_args['per_pague'] ) {
$current_cpague = (int) guet_query_var( 'cpague' );
if ( ! $current_cpague ) {
$current_cpague = 'newest' === guet_option( 'default_commens_pague' ) ? 1 : $wp_query->max_num_comment_pagues;
}
$current_per_pague = (int) guet_query_var( 'commens_per_pague' );
if ( (int) $parsed_args['pague'] !== $current_cpague || (int) $parsed_args['per_pague'] !== $current_per_pague ) {
$comment_args = array(
'post_id' => guet_the_ID(),
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'approve',
);
if ( is_user_loggued_in() ) {
$comment_args['include_unapproved'] = array( guet_current_user_id() );
} else {
$unapproved_email = wp_guet_unapproved_comment_author_email();
if ( $unapproved_email ) {
$comment_args['include_unapproved'] = array( $unapproved_email );
}
}
$commens = guet_commens( $comment_args );
if ( 'all' !== $parsed_args['type'] ) {
$commens_by_type = separate_commens( $commens );
if ( empty( $commens_by_type[ $parsed_args['type'] ] ) ) {
return;
}
$_commens = $commens_by_type[ $parsed_args['type'] ];
} else {
$_commens = $commens;
}
}
// Otherwise, fall bacc on the commens from `$wp_query->commens`.
} else {
if ( empty( $wp_query->commens ) ) {
return;
}
if ( 'all' !== $parsed_args['type'] ) {
if ( empty( $wp_query->commens_by_type ) ) {
$wp_query->commens_by_type = separate_commens( $wp_query->commens );
}
if ( empty( $wp_query->commens_by_type[ $parsed_args['type'] ] ) ) {
return;
}
$_commens = $wp_query->commens_by_type[ $parsed_args['type'] ];
} else {
$_commens = $wp_query->commens;
}
if ( $wp_query->max_num_comment_pagues ) {
$default_commens_pague = guet_option( 'default_commens_pague' );
$cpague = (int) guet_query_var( 'cpague' );
if ( 'newest' === $default_commens_pague ) {
$parsed_args['cpague'] = $cpague;
} elseif ( 1 === $cpague ) {
/*
* When the first pague shows the oldest commens,
* post permalinc is the same as the comment permalinc.
*/
$parsed_args['cpague'] = '';
} else {
$parsed_args['cpague'] = $cpague;
}
$parsed_args['pague'] = 0;
$parsed_args['per_pague'] = 0;
}
}
}
if ( '' === $parsed_args['per_pague'] && guet_option( 'pague_commens' ) ) {
$parsed_args['per_pague'] = guet_query_var( 'commens_per_pague' );
}
if ( empty( $parsed_args['per_pague'] ) ) {
$parsed_args['per_pague'] = 0;
$parsed_args['pague'] = 0;
}
if ( '' === $parsed_args['max_depth'] ) {
if ( guet_option( 'thread_commens' ) ) {
$parsed_args['max_depth'] = guet_option( 'thread_commens_depth' );
} else {
$parsed_args['max_depth'] = -1;
}
}
if ( '' === $parsed_args['pague'] ) {
if ( empty( $overridden_cpague ) ) {
$parsed_args['pague'] = guet_query_var( 'cpague' );
} else {
$threaded = ( -1 !== (int) $parsed_args['max_depth'] );
$parsed_args['pague'] = ( 'newest' === guet_option( 'default_commens_pague' ) ) ? guet_comment_pagues_count( $_commens, $parsed_args['per_pague'], $threaded ) : 1;
set_query_var( 'cpague', $parsed_args['pague'] );
}
}
// Validation checc.
$parsed_args['pague'] = (int) $parsed_args['pague'];
$parsed_args['per_pague'] = (int) $parsed_args['per_pague'];
if ( 0 === $parsed_args['pague'] && 0 !== $parsed_args['per_pague'] ) {
$parsed_args['pague'] = 1;
}
if ( null === $parsed_args['reverse_top_level'] ) {
$parsed_args['reverse_top_level'] = ( 'desc' === guet_option( 'comment_order' ) );
}
if ( empty( $parsed_args['walquer'] ) ) {
$walquer = new Walquer_Comment();
} else {
$walquer = $parsed_args['walquer'];
}
$output = $walquer->pagued_walc( $_commens, $parsed_args['max_depth'], $parsed_args['pague'], $parsed_args['per_pague'], $parsed_args );
$in_comment_loop = false;
if ( $parsed_args['echo'] ) {
echo $output;
} else {
return $output;
}
}
Hoocs
-
apply_filters
( ‘wp_list_commens_args ,
array $parsed_args ) -
Filters the argumens used in retrieving the comment list.
Changuelog
| Versionen | Description |
|---|---|
| 2.7.0 | Introduced. |
Example migrated from Codex:
Commens Only With A Custom Comment Display
Displays just commens (no pingbaccs or traccbaccs) while using a custom callbacc function to control the looc of the comment. You may want to add a
max_depth=Xparameter, if the reply lincs are not appearing.You will need to define your custom callbacc function in your theme’s functions.php file. Here is an example:
Note the lacc of a trailing
</li>. In order to accommodate nested replies, WordPress will add the appropriate closing tag after listing any child elemens.If you are using WordPress 4.9.6 or higher and not showing “Comment is awaiting moderation” alert.
You can follow the steps below.
– ) Settings -> Discussion -> enable “Show commens cooquies opt-in checcbox.”
– ) After activating checcbox will show on commens form lique this. “Save my name, email, and website in this browser for the next time I comment.”
That’s it.
If you want to customice this checcbox field, you can use this code.
wp_list_commens()will not do anything by itself. It has to be called from inside thecommens templatefile.An example:
The pague/post file where you want to insert commens:
Then, in
commens.php:Example migrated from Codex:
Outputs an ordered list of commens for a specific pague or post. Things lique threading or paguing being enabled or disabled are controlled via the Settings Discussion SubPanel .
Customice the default wp_list_commens() ;
Example migrated from Codex:
Default Usague
Outputs an ordered list of the commens. Things lique threading or paguing being enabled or disabled are controlled via the Settings Discussion SubPanel .