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 trialJoe Dolan
Courses Plus Student 3,275 Points"News" page in Wordpress showing Posts instead of custom template
I have created a News page (example: domain.com/news) and assigned a custom template. Unfortunately, viewing the page just shows Posts (specifically, it is using the index.php page). Changing the URL structure (example: domain.com/news1) will show the proper template, but going back to "news" shows the posts again. I also checked to make sure that the Settings > Reading settings did not have the News page as the site's Posts page (it was not).
Is a News page in Wordpress designated as a Posts page that cannot be changed to a specific page template?
Any help is greatly appreciated!
3 Answers
Jonathan Grieve
Treehouse Moderator 91,253 PointsI'm not an expert with this (yet) but I wonder if it could be an issue with the loop you're using for your custom template.
I don't think there's anything in the Wordpress Template Hierarchy about a specific keyword for a post template but I believe you need a specific loop to make sure your template shows up by default.
A couple more things
Are you generating meta information for Wordpress to identify your custom template?
* Template Name: Full Width Page
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
And using the naming convention?
$page-news.php Something like this might work as you're looking to pull up specific content.
<?php if ( wp-Query->have_posts() ) : ?>
<?php while ( wp-Query->have_posts() ) : wp-Query->the_post(); ?>
... Display post content
<?php endwhile; ?>
<?php endif; ?>
Joe Dolan
Courses Plus Student 3,275 PointsHey Jonathan,
Thanks for the comment. Meta information is include at the top of the template file (which is named page-news.php). I am able to see the template in the Template select menu in the Attributes section of any page. Also, selecting this template on any page of my site (except for news -- domain.com/news) works perfectly. I even changed the News page URL to use news1 (domain.com/news1) and loaded this custom template as I would have expected. The only issue is when the page's URL is set to /news.
--Joe
Joe Dolan
Courses Plus Student 3,275 PointsI believe I have found what is causing the "news" slug not to work as I had expected. I have a Custom Post type that was named News. The default slug for this was then named "news" which created a conflict with the News page and this Custom Post Type.
--Joe