Single.php loses it’s formatting

Ok, try this (untested, so excuse any minor typos/syntax errors).

I have amended so that The Loop first checks that there is Posts to show. I’ve also removed the need for $count and the addition of ' ' by adding any matches to an array, and then outputting them using join().

Hopefully I’ve not gone down the incorrect route and it will be suitable for your needs.

<?php
/**
 * The Template for displaying all single posts.
 *
 * @package WordPress
 * @subpackage WDM
 * @since WDM 1.0
 */

get_header();
?>

    <div id="primary" class="site-content">
        <div id="content" class="clear" role="main">
<?php
            if(have_posts()) : while(have_posts()) : the_post();

                    $excludedcats = array(3);
                    $categories = get_the_category();

                    $title_cats = array(); // Initialise the arry to avoid errors when checking it

                    foreach($categories as $category) :

                        /** Check to see if the category needs to be added to the class="" of the title */
                        if(!in_array($category->cat_ID, $excludedcats)) :
                            $title_cats[] = 'heading-'.$category->slug;
                        endif;

                    endforeach;

                    /** Output the title. We are checking that there were actually category headings here as well, so that class="" is properly formatted */
                    echo '<h1 class="category-heading'.
                        sprintf(__('%1$s'),
                            /** %1$s */ (!empty($title_cats)) ? ' '.join(' ', $title_cats) : ''
                        ). // end sprintf()
                    '">'; // end <h1>
                    single_post_title();
                    echo '</h1>';

                    /** Output the content */
                    the_content(); 
?>
                    <div class="related-posts-div">
                        <?php //wp_related_posts()?>
                    </div>

                    <nav class="nav-single">
                        <h3 class="assistive-text"><?php _e( 'Post navigation', 'wdm' ); ?></h3>
                        <span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'wdm' ) . '</span> %title' ); ?></span>
                        <span class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'wdm' ) . '</span>' ); ?></span>
                    </nav><!-- .nav-single -->

                    <?php comments_template( '', true ); ?>

                <?php endwhile; ?>
            <?php endif; ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>