Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm (locally) building a custom theme.

So far I have:

  • 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(); ?>

Looking forward for some clues!
Thank you very much!
Best,
L

share|improve this question
    
What is the structure in your single.php template? –  Pieter Goosen Feb 28 at 10:16
    
Edited the question with my single.php structure. Thanks! –  Leonardo Feb 28 at 11:03
    
Try removing the Template Name of your single.php. I'm not sure about this, but I think this could be confusing to the template structure. –  fischi Feb 28 at 11:18
    
have you disabled all plugins? output the query object in your index.php file to see what the main query vars look like, this is how WordPress decides what template to load. The contents of your single template are completely irrelevant, despite what others suggest here. Add var_dump($wp_query); somewhere in the template, then edit your question and add that output. –  Milo Mar 6 at 23:50

2 Answers 2

Your structures is completely wrong. Remove the template name from your index and single.php template. 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:

<?php
            // Start the Loop.
            while ( have_posts() ) : the_post(); ?>

        <?php
                Content of the loop goes here, in your case the_content();
            endwhile;
        ?>

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

share|improve this answer

I followed the advices but anything is working.

my single.php is now literally:

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

        <?php the_content();
            endwhile;
        ?> 
<?php get_footer(); ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.