WP ::: Màu mè cho phần Ý kiến mới

Đợt trước chép đại một đoạn mã (hình như từ trong ./wp-admin/index.php thì phải) để làm danh sách “Ý kiến mới”. Hôm nay ngứa tay cho thêm màu mè cho sinh động :P. Cụ thể là: Trong vòng 24 giờ thì đỏ, trong khoảng 24 giờ tới 48 giờ thì cam,… Vẫn quan điểm là không làm trình bổ sung (plugin) làm chi cho mệt. Cứ tiêu bản (template) mà chơi. Muốn đút vào chỗ nào thì đút, tuỳ.

<?php
	$comments = $wpdb->get_results("SELECT comment_ID, comment_post_ID, comment_date_gmt 
	FROM $wpdb->comments
	WHERE comment_approved = '1'
	ORDER BY comment_date_gmt DESC LIMIT 5");
	if ( $comments ) { ?>
<h3>Ý kiến mới</h3>
<ul>
<?php
	foreach ($comments as $comment) {
		$ct = $comment->comment_date_gmt;
		$ctime = gmmktime(substr($ct,11,2),substr($ct,14,2),substr($ct,17,2),substr($ct,5,2),substr($ct,8,2),substr($ct,0,4));
		$clife = gmdate('U') - $ctime;
		$class = ($clife >= 345600) ? '' : ( ($clife >= 172800) ? ' class="commentveryold"' : ( ($clife >= 86400) ? ' class="commentold"' : ' class="commentnew"') );
		echo "<li{$class}><a href=\"" . get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . "</a></li>\n";
	}
?>
</ul>
<?php } ?>

Đấy là PHP.

Còn CSS thì quá đơn giản, đại loại là:

#sidebar ul li.commentnew {
	list-style:url(bullet-red.png);
}

Thế thôi.


Chuyên mục:

,