Pégalo tal cual en la ubicación deseada en tu tema… Ten en cuenta que el fragmento completo muestra el correo electrónico del autor del comentario, lo cual podrías querer ocultar para respetar su privacidad.
<?php
$comments = get_comments( array(
'number' => 10, // set comments amount here
'status' => 'approve' // set comment type here
) );
foreach($comments as $eachComment){
// COLLECTION THE DATA AND SETTING VARIABLES
$commentID = comment_ID;
$commentAuthorEmail = $eachComment->comment_author_email;
$commentPostId = $eachComment->comment_post_ID;
$commentPostTitle = get_the_title( $commentPostId );
$commentPostUrl = get_permalink( $commentPostId );
$comment_sidebarnumber = get_comments_number( $commentPostId );
global $wpdb;
$userCommentCount = $wpdb->get_var('SELECT COUNT('.$commentID.') FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . $commentAuthorEmail . '"');
echo '<div style="border: 1px solid #ccc; padding: 10px;">';
echo '<ul style="margin: 0px;">';
echo '<li>Written By: '. $eachComment->comment_author .'</li>';
echo '<li>Commented to: <a href="'.$commentPostUrl.'">'. $commentPostTitle .'</a></li>';
echo '<li>Commented on: '. $eachComment->comment_date .'</li>';
echo '<li>Author Website: '. $eachComment->comment_author_email .'</</li>';
echo '<li>Author Email: '. $eachComment->comment_author_email .'</</li>';
echo '<li>Author has: '. $eachComment->comment_author .' responded '. $userCommentCount .' times in total</</li>';
echo '</ul>';
echo '<p style="padding: 10px;"><strong>'. $eachComment->comment_author .' כתב</strong>: '. $eachComment->comment_content .'</p>';
echo '</div>';
}
?>
Nota: Si es la primera vez que agregas fragmentos de código en WordPress, consulta nuestra guía sobre cómo agregar fragmentos de código correctamente en WordPress, para que no rompas accidentalmente tu sitio.
Si te gustó este fragmento de código, considera echar un vistazo a nuestros otros artículos en el sitio como: Los 7 mejores plugins de WordPress para GDPR para crear un sitio compatible con GDPR y cómo crear un formulario de donaciones de WordPress.
Comentarios Deja una respuesta