The way I would approach this would be to create a template part called related-posts.php or something of the sort. In it, I would go through every link in the post’s content and check to see if that url corresponds to another post (using the url_to_postid()
function). I would then save all the non-zero id’s to an array and finally, I would run a secondary wp loop to display those posts the way you want to (ie. thumbnail + title). Something like this:
(This code was partially modified from this answer)
$cont = get_the_content();
$related_post_ids = array();
//Only proceed if there is content
if ( !empty( $cont ) ) {
// Get page content
$html = new DomDocument;
libxml_use_internal_errors(true); //See https://stackoverflow.com/questions/9149180/domdocumentloadhtml-error
$html->loadHTML( '<?xml encoding="UTF-8">' . $cont );
libxml_use_internal_errors(false);
$html->preserveWhiteSpace = false;
// Loop through all content links
foreach( $html->getElementsByTagName( 'a' ) as $link ) {
// Get link href
$link_url = $link->getAttribute( 'href' );
//If link href is not empty
if( !empty( $link_url ) ){
//Try to find the post that is being linked
$linked_postid = url_to_postid( $link_url );
//If we find the post, add it to the related_post_ids array
if($linked_postid != 0){
array_push($related_post_ids, $linked_postid);
}
}
}
}
//If we found other posts linked in the content
if( count($related_post_ids) > 0 ){
//Run a secondary loop to display the related posts
$q_args = array(
'post_type' => 'any',
'post_status' => 'publish'
'posts_per_page' => 3 //Limit how many you show
'post__in' => $related_post_ids, //Get only the posts we found
'orderby' => 'post__in' //Order them in the same order as the links appear in the post's content
);
$relposts_query = new WP_Query( $q_args );
if ( $relposts_query->have_posts() ) :
// Start the Loop
while ( $relposts_query->have_posts() ) : $relposts_query->the_post();
//Add your markup here, you may use the_post_thumbnail( ) for the featured image and the_title( ) for the article title
endwhile;
endif;
wp_reset_postdata();
}else{
/*
* You may want to write some backup code here, what to display if the post in question
* did not have any links to other posts.
*/
}
I have not tested this code so it may have some errors I did not anticipate. However, it should be enough to guide you in the right direction.