Nützliches

Letzte Kommentare mal anders

WordPress bietet zwar ein hauseigenens Widget an, mit dem die letzten Kommentare in der Sidebar angezeigt werden können, aber manchmal ist dies einfach nicht zufriedenstellend. Mit einem kleinen Hack im aktiven Theme kann man rasch ein weitaus interessanteres Ergebnis erzielen!

Fügt einfach in der sidebar.php eures Theme folgenden Code an der richtigen Stelle ein, das heisst nach einem </li>.

<li><h2>Letzte Kommentare</h2>
	<ul id="recent_comments">
		<?php
		global $wpdb;
		$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID,
		SUBSTRING(comment_content,1,80) AS com_excerpt
		FROM $wpdb->comments
		LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
		$wpdb->posts.ID)
		WHERE comment_approved = '1' AND comment_type = '' AND
		post_password = ''
		ORDER BY comment_date DESC
		LIMIT 4";
		$comments = $wpdb->get_results($sql);
		$output = $pre_HTML;
		foreach ($comments as $comment) {
		$output .= "\n<li><a href=\"" . get_permalink($comment->ID) .
		"#comment-" . $comment->comment_ID . "\" title=\"on " .
		$comment->post_title . "\">" .strip_tags($comment->com_excerpt).
		"...</a>";
		}
		$output .= $post_HTML;
		echo $output;?>
	</ul> <!-- END -->
</li>

Alternativ könnt ihr natürlich auch mit einem Plugin PHP-Code in Widgets erlauben und die Datenbankabfrage dort hineinkopieren! Das Resultat sollte dann so aussehen wie hier.

3 Kommentare zu “Letzte Kommentare mal anders”

  1. FirstDayBlack am 17. Januar 2009 um 15:00 | Permalink

    Klasse. Das habe ich sofort eingebaut.

  2. MiFuPa am 20. Januar 2009 um 19:46 | Permalink

    Ich auch, sieht gut aus :)

    Danke!

  3. marvin am 8. Januar 2012 um 21:05 | Permalink

    funktioniert. perfekt danke!;)

6 Pingbacks

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

*

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>