This is a specific solution for related posts with Wordpress. It requires some hard coding and plugins, I'm sure there are other ways to do this but I haven't found anything "out of the box" with the following requirements:

  1. Should work with a multi language blog
  2. Must allow different css styles depending on the category of the specific post
  3. One post can have two or more groups of related entries

This can be useful for a records company, a bookstore, a movie store, etc… You might have a band or an author with many records or books (related posts) and different styles or genres, or a book written by two authors, etc.

An image is worth a thousand words, so here is what I needed:

You'll find links below to all the pieces of code I've put together to make this work.

The first things we need are the Get Custom Field Values plugin by Scott Reilly and, if your blog is multilanguage you also need the Language Switcher by Jennifer Hodgdon

Custom Fields to the Rescue

Relationships between posts are easy thanks to the Custom Fields. Just create a new custom field and give it a relevant name to the information you are going to store in it

The Code

To make sure our related entries are only visible when we are on a single post page, we need this piece of code

 
<?php if (is_single()) { 
 

If you want your related entries on the sidebar, you'll be obliged to work outside The Loop, we can achieve this using the WP_Query class

 
$relatedPosts = new WP_Query();	
 

Now we have to make a call to the “Get Custom Field Values” plugin. If our post has a custom field, we retrieve all the entries that share that value. I've used an underscore to divide name and surname, so "Stanley_Kubric" will be replaced by "Stanley Kubric" using the php function "str_replace". If your blog is multilanguage, you can retrieve the language variable to display your related entries title in the selected language

 
<?php 
$keyPerson = c2c_get_custom('Person');
if ($keyPerson != '') {     
    $relatedPosts->query("meta_key=Person&meta_value=$keyPerson");
    global $langswitch_lang_pref;
    if( $langswitch_lang_pref == 'en' ) {
        $person_name = str_replace("_", " ", $keyPerson);?>
        <h3>More Projects by <?php echo $person_name;?></h3>
    <?php } else {  ?>
        <h3>Mas proyectos por <?php echo $person_name;?></h3>
        <?php } ?>
 

Obviously, we don't want the current entry on the list, to avoid that, we have to get the post ID outside the Loop as PHP variable, then we have to apply different styles depending on each entry's categories. We can use the slugs as css classes (don't forget that you have to add the classes to your style sheet). Also, we have to display an alternative message, just in case there weren't related entries for the current post. To keep it simple and clear, I haven't added the code to display this message in multiple languages, but you can figure that out looking at the code above.

 
   <ul><?php $current_post_id = $post->ID ?>
    <?php while ($relatedPosts->have_posts()) : $relatedPosts->the_post();
        $related_post_id = $post->ID;
        if ($current_post_id != $related_post_id) { ?>
            <li><a class="
            <?php $categories =  get_the_category($related_post_id);
                foreach ($categories as $cat) {
                    $css_cat = $cat->slug;
                    echo $css_cat;
                } ?>" 
                href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
        <?php } ?>
    <?php endwhile; ?>
<?php } else {  ?>
    <li>We haven't found related entries for this author, please let us know if you've found one</li>
<?php } ?>
</ul>       
 

Some Wordpress themes can make this code appear on the home page. To avoid that, you can provide an alternative to display the most recent post:

 
    <?php } else {  ?>
        <ul>
        <?php
        $recentPosts = new WP_Query();
        $recentPosts->query('showposts=5');
        ?>
        <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
        <li><a class="
            <?php $categories =  get_the_category($related_post_id);
                foreach ($categories as $cat) {
                    $css_cat = $cat->slug;
                    echo $css_cat;
                } ?>" href="<?php the_permalink() ?>" rel="bookmark">
                <?php the_title(); ?></a></li>
        <?php endwhile; ?>
        </ul>       
<?php  } ?>
 

The code in a single block:

 
<div class="boxtop">
<?php if (is_single()) { 
    $relatedPosts = new WP_Query();	
    $keyPerson = c2c_get_custom('Person');
    if ($keyPerson != '') {     
        $relatedPosts->query("meta_key=Person&meta_value=$keyPerson");
        global $langswitch_lang_pref;
        if( $langswitch_lang_pref == 'en' ) {
            $person_name = str_replace("_", " ", $keyPerson);?>
            <h3>More Projects by <?php echo $person_name;?></h3>
        <?php } else {  ?>
            <h3>Mas proyectos por <?php echo $person_name;?></h3>
            <?php } ?>
            <ul><?php $current_post_id = $post->ID ?>
            <?php while ($relatedPosts->have_posts()) : $relatedPosts->the_post();
                $related_post_id = $post->ID;
                if ($current_post_id != $related_post_id) { ?>
                    <li><a class="
                    <?php $categories =  get_the_category($related_post_id);
                        foreach ($categories as $cat) {
                            $css_cat = $cat->slug;
                            echo $css_cat;
                        } ?>" 
                        href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
                <?php } ?>
            <?php endwhile; ?>
        <?php } else {  ?>
            <li>We haven't found related entries for this author,
                  please let us know if you've found one</li>
        <?php } ?>
        </ul>       
    <?php } else {  ?>
        <ul>
        <?php
        $recentPosts = new WP_Query();
        $recentPosts->query('showposts=5');
        ?>
        <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
        <li><a class="
            <?php $categories =  get_the_category($related_post_id);
                foreach ($categories as $cat) {
                    $css_cat = $cat->slug;
                    echo $css_cat;
                } ?>" href="<?php the_permalink() ?>" rel="bookmark">
                <?php the_title(); ?></a></li>
        <?php endwhile; ?>
        </ul>       
<?php  } ?>
</div>