Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Backwards-Compatible Comment Templates

The easiest way to accommodate for both old (pre-2.7) and new (2.7+) WordPress comment loops is to create two different versions of the comments template and then use some conditional logic to process the correct file. Place the 2.7-compatible code from the previous section into your default comments.php file, and then place your existing (pre-2.7) comments code into a file called legacy-comments.php. Once you have both of these files setup and included among your theme files, place the following function in your theme’s functions.php file:

<?php add_filter('comments_template', 'legacy_comments');

function legacy_comments($file) {
	if(!function_exists('wp_list_comments')) : // WP 2.7-only check
		$file = TEMPLATEPATH.'/legacy-comments.php';
	return $file;
} ?>

This code will then check for the presence of the new wp_list_comments() function. If it exists, then the version of WordPress is at least 2.7, and the default comments.php file will be used. If the new function doesn’t exist, we have a dinosaur on our hands and so the legacy comments file will be used instead.