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


Trying to build a Wordpress Theme


So, I'm trying to build a Wordpress theme. I've made a folder called testwp that contains all the Wordpress files. When I put localhost/testwp/ in the browser, it shows me the front-page.php file. But if I put in localhost/testwp/front-page.php, it turns up as a blank page. Why is that?

//Oops, I think I know why...the front-page.php file is not directly in the testwp folder.

//When I put in the path ... http://localhost/testwp/wp-content/themes/mytheme/front-page.php, it still doesn't show up

2 Answers

Andrew Shook
Andrew Shook
31,709 Points

Robin, WordPress doesn't work like a standard website. WordPress uses what is call a Front Controller design pattern. This means at all request to example.com go to WordPress's index.php file. To better explain I'll us an example request to www.example.com/about-us/history. Once the server that hosts example.com receives the request, is looks for the folder where the example.com site is located, which happens to be a WordPress site. Inside the site's root folder is a file called a .htaccess file. This file is read by server, and directs all incoming requests to the index.php file in WordPress's root folder. The .htaccess file also separates the parts of the request after example.com from the domain name and passes that to WordPress for use later. In this case that would be about-us/history. Once .htaccess file is finished the server then loads WP's index.php file, because that's what the .htaccess file told it to do. The index.php file then loads the WP program and begins processing the remainder of the request, about-us/histoty. I won't try to explain everything WP does to return a web page, because that could to a small book, but I will try to explain the basics. First WP runs through some logic and database queries to try to figure out what information needs to load from the database. After that it retrieves the needed information and then make figures out what the active theme is. From there, It runs through some more logic and picks the correct template and executes the code inside the template file. Finally, after all the is done it returns the finished template file's HTML to the requesting browser.

So the reason you can't go to the front-page.php template is because WP is excepting a request that corresponds to a page or post in its database and not an actually file. Hope this helps.

Have you set your static page under Settings -> Reading -> Static Home Page? Also, did you called the template name in the front-page.php document?

I have a page that displays with my 3 blog posts when I put in localhost/testwp/

I just don't know why it doesn't appear with the full path localhost/testwp/wp-content/themes/mytheme/front-page.php ?

The same thing happens with the file localhost/allisongrayce.com

It shows the front-page.php file, but not if I put in the full path localhost/allisongrayce.com/wp-content/themes/wpportfolio/front-page.php