Forgive me, I'm a PHP noob and writing too much of it makes my eyes glaze over; I'm sure this is a super simple solution and probably a dumb question.

I'm working on a custom theme where I want to use index.php to show excerpts on the blog (home) pages and all archive/category pages. I created a "post-teaser" template part to accomplish this, called from index.php like so:

<?php /* Start the Loop */ ?>
  <?php while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'post-teaser' ); ?>
  <?php endwhile; ?>
<?php else : ?>

The issue is that now any permalink takes me to a single instance of this "post-teaser" template (which only includes thumbnail, title, excerpt, and category), rather than the full post. I can easily create a "post-single" template, but how can I call that from index.php only on single posts?


You do not need to explicitly call the post-single template, this is something wordpress is doing automagically for you based on the URL structure. For archive URLs the archive template will be "called" while for single posts the single template will be "called. There are fullbacks with the ultimate one is the index.php template.

For a better understanding of the structure and fallbacks look at the template hierarchy

  • Ok, this is what I thought, buuuuut I had the single template named "post-single.php" instead of "single-post.php" ...I knew this was a dumb question, but thank you for that helpful link!
    – sugarfiend
    Apr 26 '18 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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