Recent Comments Section

// Sekcja wyswietlajaca 3 najnowsze komentarze 2 sposoby // Sposob pierwszy <?php $args = array( 'status' => 'approve', 'number' => '3', ); $recent_comms = get_comments($args); foreach ( $recent_comms as $comment): $date = new \DateTime($comment->comment_date_gmt); ?> <section> <header> <small> <?php echo $comment->comment_author;?> w dniu <?php echo $date->format('d.m.Y'); ?> o godzinie <?php echo $date->format('G:i:s'); ?> </small> <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo cutText($comment->post_title, 27);?></a> </header> <?php echo get_avatar( $comment->user_id,69);?> <!-- id uzytkownika, rozmiar awataru--> <blockquote> <?php echo $comment->comment_content;?> </blockquote> </section> <?php endforeach; ?> // Sposob drugi z wykorzystaniem SQL <?php function fetchRecentComments($limit = 3) { global $wpdb; //dla bezpieczeństwa $limit = (int)$limit; $res = $wpdb->get_results(" SELECT C.*, P.post_title FROM {$wpdb->comments} C LEFT JOIN {$wpdb->posts} P ON C.comment_post_ID = P.ID WHERE comment_approved = 1 ORDER BY comment_date_gmt DESC LIMIT {$limit} "); return $res; } ?> ^ <?php //Zamiast $recent_comms = get_comments($args); //Uzywam $recent_comms = fetchRecentComments(3); ?>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.