'single.php in WordPress does not render anything

I have code in my single.php

<?php 
get_header(); ?>

<?php if(have_posts()):  ?>
<?php   while(have_posts()): the_post(); ?>
            <h1><?php the_title(); ?></h1>
            <p><?php the_category(', ');?><?php the_date(); ?> by <?php the_author(); ?></p>
            <div><?php the_content(); ?></div>
<?php   endwhile; ?>    
<?php else:  ?>
<?php   wp_redirect(get_bloginfo('siteurl').'/404', 404); exit; ?>
<?php endif; ?>


<?php 

get_footer(); ?>

but when I launched my site nothing happened. However, when I put this code in index.php everything is displayed as should. Does anyone know what can be problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source