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

Timothy Tuite
Timothy Tuite
5,429 Points

loops on different pages

I am trying to make a news web site from scratch. I have several different categories of posts (news,features,sports opinions). I've set up these categories and i understand the WP_query() function and then using the category number but how do create the actual pages for them? Do i just add a News.php or sports.php

1 Answer

You'll have to create a custom template for each page. You can create a function that automatically detects which page you're on and inject the necessary code but let's just deal with the simple solution here. To create a page template you could create it and when making a new page from the dashboard just select that template. You must put the following code at the top of your template.

<?php
/*
 * Template Name: Sports Page
 * Description: Sport page containing etc..
 */

// you code goes here including your header, loop etc...

Here's indepth info on the topic here: http://www.smashingmagazine.com/2015/06/19/wordpress-custom-page-templates/