Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress From Bootstrap to WordPress Create Bootstrap Styled Theme Templates Creating a Portfolio Single Page

Rebecca Jensen
Rebecca Jensen
11,580 Points

Why am I getting the index.php file instead of my single-event.php file?

I am creating page-event.php and single-event.php in place of the page-portfolio and single-portfolio files in this tutorial.

My page-event.php seems to work fine. It is listing the links I want; but when I click on the links, they go to the index.php template instead of my single-event.php template.

What might I have missed?

I confirmed that my Custom Post Type slug is "event". My Custom Fields are set to show if Post Type = event

Edit: updated with code.

page-event.php

<?php
/*
    Template Name: Event List
*/
?>
<?php get_header(); ?>


<div class ="row"> 

  <div class="col-lg-12" id="no-pad"> 

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

        <div class="page-header">
            <h1><?php the_title(); ?></h1>
            <hr></hr>
        </div>

        <?php the_content(); ?>

      <?php endwhile; else: ?>

        <div class="page-header">
          <h1>Oh no!</h1>
          <hr></hr>
        </div>
        <p>We've dropped our compass. page event-list template</p>

      <?php endif; ?>


  </div> <!-- close col-12 -->

</div><!-- close opening row -->


<!-- begin content -->
<div class="row">

    <?php
      $args = array(
        'post_type' => 'event'
        );
      $the_query = new WP_Query( $args );
    ?>

  <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    <div class="col-lg-12 event-list">

      <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>

    </div><!-- close col -->

</div><!-- close row -->

  <?php endwhile; endif; ?> <!-- end have_posts -->


<?php get_footer(); ?>

single-event.php

<?php get_header(); ?>

<div class ="row lg-mrg-top"> <!-- division of left/right begins after this (this row contains all) -->

<!-- ###########main content left########## -->
  <div class="col-lg-9 col-md-9 col-sm-9 more-pad-right no-pad-left"> 

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

        <?php the_content(); ?>

      <?php endwhile; else: ?>

        <div class="page-header">
          <h1>Oh no!</h1>
          <hr></hr>
        </div>
        <p>We've dropped our compass!!!! single-event template.</p>

      <?php endif; ?>

  </div> <!-- close main content left-->

<!-- ##############sidebar content right#############-->
<?php get_sidebar( 'event' ); ?>

</div><!--end the row that holds both left/right content -->


<?php get_footer(); ?>

Hi Rebecca,

Can you post your code please?

Thanks

-Rich

Rebecca Jensen
Rebecca Jensen
11,580 Points

Also, I did have a custom post type of "event" (or "events"?) that I deleted and made again. Not sure if that would have any affect.

Update:

I made new single-test.php and page-test.php files to see if it had anything to do with the name. I am running into the same problem with the test files (in which I pasted the same code from my event files).

Update:

Also, I should note that I don't event get the single post CONTENT in the index.php template. I just get an index.php error message.

Rebecca Jensen
Rebecca Jensen
11,580 Points

Also, I used the Custom Post Types plug-in to create my post types. I didn't register it manually in the functions.php folder.

But this tutorial uses the CPT UI plug-in with no issue.

If you visit the custom post type direct using the slug do you run in to the same problems?

-Rich

Rebecca Jensen
Rebecca Jensen
11,580 Points

Well, crap. I tried deactivating the CPT UI plugin and adding post types manually, and now I have a slew of other problems. I can't see old media that I've uploaded (the upload dialogue window just thinks and thinks), and when I save changes, I am led to a blank white screen.

This is the manual code I tried:

function my_custom_posttypes() {
    $args = array(
    'public' => true,
    'label' => 'event'
    );
    register_post_type( 'event', $args );
}

add_action( 'init', 'my_custom_posttypes' );

I've spent the whole day trying to get WP to recognize my single-event.php file. Now that I have spawned a bunch of other problems, I may re-do everything from scratch after I cry.

Sorry to hear you're having more problems. With regard to the original problem, I'm not saying this is the answer but it may help.

The Custom Post Type page of the Codex states:

Note: In some cases, the permalink structure must be updated in order for the new template files to be accessed when viewing posts of a custom post type. To do this, go to Administration Panels > Settings > Permalinks, change the permalink structure to a different structure, save the changes, and change it back to the desired structure.

Have you managed to get the templates working using the same post type as the videos?

-Rich

2 Answers

Sarah Jee Watson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sarah Jee Watson
UX Design Techdegree Graduate 28,197 Points

I had this issue too. Created a CPT called 'project' instead of 'portfolio'.

The main projects (summary) page was created and called page-project.php The single project page was created and called single-portfolio.php

When I clicked on the project links on the main projects (summary) page, they all went to index.php

Renaming my 'single-portfolio.php' to 'single-project.php' fixed this issue!

Rebecca Jensen
Rebecca Jensen
11,580 Points

I ended up just starting over, and it worked on the second go-around. I think that something went bonkers when I messed with manually installing custom post types AND turning them on/off within Wordpress. Unfortunately I don't have a clear answer to post here, but it has been resolved!

Glad that you were able to fix your issue with a re-name, Sarah!