Getting index.php instead single.php for displaying posts

I’m (locally) building a custom theme.

So far I have:

Read More
  • index.php
  • single.php
  • page.php
  • custom page template called about-page.php
  • two different headers: one for default use and one for the single.php

NO functions.php;
NO custom taxonomy;
Permalink settings > Common settings : default

My index.php has a list of posts (all of those belonging to a specified category), when I click on one of those posts I end to the index.php BUT with the right custom header (header I created for the posts, it’s called header-single.php).

So, I’m getting the index.php istead of the single.php

I read around other people had the same problem with the word “year” or some other Reserved Terms. I don’t think it’s my case.

In my home page I have:

<?php
/**
 * Template Name: Front Page Template
 */
get_header(); ?>
<nav id="menu">
        <ul class="postlist">
            <?php
                $lastposts = get_posts('numberposts=20&orderby=date&cat=9');
                foreach($lastposts as $post) :
                setup_postdata($post);
                ?>
                    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a</li>
                <?php endforeach; ?>
            </ul>
</nav>
<?php get_footer(); ?>

EDIT

Here’s the structure of my single.php

<?php
/*
 Template Name: Single project
  */
get_header(); ?>

<div id="flex-container">   
//something
</div>

<div id="read">
    <a>READ</a>
</div>
<div id="read_slider">
    <div id="read_close">
        <a>CLOSE</a>
    </div>

    <div id="read_text">
        <?php the_content(); ?>
    </div>  
</div>

</div>
<?php get_footer(); ?>

Related posts

3 comments

  1. Your structures is completely wrong. Remove the template name from your index.php and single.php templates. You only should use those if you create a custom page.php template to let wordpress know it is a custom page. This should apply to your about-page.php, which is also wrongly named, it should be page-about.php. Your index.php looks about right, but your single.php is bit of a mess, that is why wordpress skip that template completely and uses index.php instead.

    There is no loop defined in your single.php. The loop looks something like this:

    // Start the Loop.
    while ( have_posts() ) { 
        the_post(); 
    
        //Content of the loop goes here, in your case 
        the_content();
    
    }
    

    Go and have a look at the default themes in the WordPress core and see how their templates are put together and how your structures should look like. Working from those themes will guide you in the right direction

  2. I had the same problem with neither the single-CUSTOM-TYPE.php nor the single.php being rendered after clicking the single-post-link…. only index.php instead of the correct file…

    What helped me was a simple change back to Standard Permalinks in “Settings” -> “Permalinks” and a restore back to “Name of the Post” (Beitragsname)….

    Maybe this might help someone else as well

  3. I followed the advices but nothing is working.

    My single.php is now literally:

    <?php get_header(); ?>
    <?php while ( have_posts() ) : the_post(); ?>
    
            <?php the_content();
                endwhile;
            ?> 
    <?php get_footer(); ?>
    

Comments are closed.