Minimal Template for Relevanssi Related Posts

Relevanssi Pro offers a related posts feature, that simply implements related posts below posts or pages. Because I don’t like the default template, I created my own minimal version. If you want to use this minimal version, create a new file templates/relevanssi-related.php in your theme or child theme. The content of this file should be:

<?php

if ( ! empty( $related_posts ) ) {
	echo '<div class="related-posts">';
	echo '<h3>' . esc_html( 'Related Posts', 'relevanssi' ) . '</h3>';

	echo '<ul>';
	foreach ( $related_posts as $related_post_id ) {
		$the_post = get_post( $related_post_id );
		$link     = get_permalink( $related_post_id );

		$title = $the_post->post_title;
		echo '<li><a href="' . $link . '">' . $title . '</a></li>';
	}
	echo '</ul>';
	echo '</div>';
}