Basic functions for working with WordPress comments open

Basic functions for working with WordPress comments

Displays comments of posts (posts, pages). The function can take a number of parameters and is used in the template to display a list of comments on a post/page. Some of the settings can be configured in the admin panel.

This function must be preceded by a call to the comments_template() function, which receives the comments to be output from the database. If this is not done, then the second parameter $comments must be specified, otherwise the function will not output anything.

<?php wp_list_comments(); ?>

A function that displays the number of comments. Including notifications and pings.

<?php get_comments_number(); ?>

can be used in construction

$num_comments = get_comments_number();

if ( comments_open() ) {
	if ( $num_comments == 0 ) {
		$comments = __('No Comments');
	} elseif ( $num_comments > 1 ) {
		$comments = $num_comments . __(' Comments');
	} else {
		$comments = __('1 Comment');
	}
	$write_comments = '<a href="' . get_comments_link() .'">'. $comments.'</a>';
} else {
	$write_comments =  __('Comments are off for this post.');
}

A function that displays pagination for WordPress comments. In the parameters you can specify the number of comments per page, etc.

<?php the_comments_navigation(); ?>
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation