брошу идею, может у кого возникнет интерес сделать.
На главной, под каждым постом выводить последний коментарий этой новости или два… Ну или самый рейтинговый(Топовый).
Сегодня при помощи AI, получилось это сделать. Делюсь что получилось. Если где-то код написан как говно, то это делал я. УЖ извиняйте!
При нажатии на коммент, открывается сам коментарий в посте. (#comment_22)
В default_list.tpl куда вам надо:
<?php $post_id = $item['id']; $last_comment = null; // Get the last comment for this post from db $config = cmsConfig::getInstance(); if (isset($config->db_prefix)){ $db_prefix = $config->db_prefix; $sql = "SELECT c.content, c.date_pub, c.id as comment_id, u.nickname, u.id as user_id, u.slug as user_slug, u.avatar, p.slug as post_slug, p.title as post_title FROM ".$db_prefix."comments c JOIN ".$db_prefix."users u ON c.user_id = u.id JOIN ".$db_prefix."con_posts p ON c.target_id = p.id WHERE c.target_id = ".$post_id." ORDER BY c.id DESC LIMIT 1"; $result = cmsDatabase::getInstance()->query($sql); if($result && $result->num_rows > 0){ $last_comment = $result->fetch_assoc(); } }else{ echo "Error: Prefix not available."; return; } if ($last_comment){ $comment_url = '/'.$last_comment['post_slug'].'.html#comment_'.$last_comment['comment_id']; echo "<div class='last-comment' onclick=\"window.location.href = '".htmlspecialchars($comment_url)."';\" style='cursor: pointer;'> <p>"; if(!empty($last_comment['user_slug'])){ $profile_url = '/users/' . $last_comment['user_slug']; } else { $profile_url = '/users/' . $last_comment['user_id']; } $avatar_html = ''; if (!empty($last_comment['avatar'])) { $avatar_html = html_avatar_image($last_comment['avatar'], 'small', $last_comment['nickname'], true); } else { $avatar_html = html_avatar_image_empty($last_comment['nickname'], 'avatar__small'); } echo "<span class='comment-avatar mr-1'><a href='" . htmlspecialchars($profile_url) . "'>" . $avatar_html . "</a></span>"; echo "<span class='comment-author'><a href='" . htmlspecialchars($profile_url) . "'>".htmlspecialchars($last_comment['nickname'])."</a></span>"; echo "<span class='comment-time'>".lang_date(date('j F Y H:i', strtotime($last_comment['date_pub'])))."</span><br>"; echo $last_comment['content']; echo "</p></div>"; } ?>
Ну и стили(меняем на свой вкус):
.comment-avatar img{ width:20px; border:1px solid var(--gc-border-light); border-radius:50%; } .last-comment { margin-top: 10px; /* Adds spacing above the comment */ padding: 5px; /* Adds padding inside the comment */ background-color: var(--body-bg); border-radius:10px; margin-left: -5px; margin-right: -5px; } .last-comment p { font-size: 0.9em; /* Adjusts the content font size */ margin-bottom: 0.5rem; padding-left: 5px; } .last-comment .comment-author { color: var(--dark-color); /* Sets a color for the author's name */ margin-right: 0.5rem; } .last-comment .comment-time { font-size: 0.8em; /* Adjusts the timestamp font size */ color: var(--light-color); /* Sets a color for the timestamp */ }
Было интересно. Может кому пригодится.