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

Alessandro Maculotti
Alessandro Maculotti
4,954 Points

Wordpress Template Hierarcly

Hi everybody! I have a problem with wp hierarchy. I have created a custom template portfolio, and I have assigned it on the page in the wordpress backend.

page-portfolio-col1.php

When I click the post, I would like that the landing page is on a single-portfolio-col1.php. But it doesn't work, automatically it redirects to "page.php"

Why does it happen?

Thanks.

5 Answers

Eve L.
PLUS
Eve L.
Courses Plus Student 9,023 Points

Ah, I think I understand what you are trying to do, but I can't figure out how to do it with categories. Could you make a custom post type instead? That seems pretty straightforward to use single-$posttype.php. http://codex.wordpress.org/Template_Hierarchy

Sorry, I can't help. Maybe somebody else will try. Also, your English is much better than my Italian ;)

Eve L.
PLUS
Eve L.
Courses Plus Student 9,023 Points

Can you clarify...are you trying to set a POST or a PAGE to use your custom template?

Alessandro Maculotti
Alessandro Maculotti
4,954 Points

Sure.. =) So I have a custom template (page-portfolio-col-1.php) that works. This custom template load all posts that have a specific category_name

  <?php 
$args = array(
      'category_name' => 'arrampicata'
  );
$the_query = new WP_Query( $args );
?>
 <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
 <a href="<?php the_permalink() ;?>"><?php the_title() ;?></a>

When I click on title i would like that arrive on single-portfolio-col-1.php or single.php, but this don't work and I arrive on page.php

I hope this is more understandable than my precedent answer. And sorry for my english bad.

Alessandro Maculotti
Alessandro Maculotti
4,954 Points

Thanks for everything!! Really =) . I have found the problem so was so simple.. I have created a page with the same name of the post and "the_permalink()" creates a conflict.