1
votes

[NEW AT WORDPRESS]

I'm creating my own wordpress theme with own css etc etc. I've managed to get everything good in the index.php file, and I'm trying to make the other pages as well now.

When I make the home.php, blog.php, about.php and contact.php file (in my theme folder) they don't link to it. I'm following the "WordPress 3: Creating and Editing Custom Themes with Chris Coyier" on Lynda.com and the example shows that whenever you make a file with the same name as your page, it takes that directly (which works at his tutorial).

Anyone that could know what is going on?

Example: I got a file blog.php in my theme folder, and when I go to www.mydomain.com/blog the loaded file is the index.php file, instead of the blog.php file

2
Silly question, but have you actually got pages called "blog", "about" etc. in your WP?Raad
Did you add in the page template name in your new page files? <?php /* Template Name: My Custom Page */Sean Henderson
I'm not sure what you mean. You've got a file called, say, 'blog.php' in your theme folder - but what doesn't link to what? Your blog.php file (in your site) doesn't pull up the contents of that file for theming?andrewsi
@Raad Yep. All the pages are in the "pages" section. I also made a dynamic menu out of the 4 pages trough Appearance->Menus.Warre Buysse
@WarreBuysse Try using the page slug in the template name instead of the page title.Sean Henderson

2 Answers

1
votes

There are two ways you can get this working using custom page templates.

  1. Create a template for one specific page using the page slug or ID. In this case, change the name of the php files like this to match the name of the page you created in the UI: page-home.php, page-blog.php, page-about.php and page-contact.php

  2. Much more flexible is to create a custom template that can be used on ANY page. Just add the template name to the top of the php file like so (inside the php block):

    /* Template Name: My Home Page Template */

Then edit the pages and select your custom template from the template dropdown menu (on the right hand side I think, if its visible).

Reference this page for more info: https://developer.wordpress.org/themes/template-files-section/page-template-files/

0
votes

Found the solution to my (silly) problem.

Creating a page in your theme directory & adding the template comment at the top of your php file isn't enough. You need to go to the admin panel->pages->YOUR PAGE-> and check out the page attributes. There you can link the page to a certain template: http://d.pr/i/a0m0