I have a custom post type where I can create pages in.("article.php")
It automatically uses the template "single.php" when I create a page, although I want to change some things in it without effecting some other pages on the website.
I tried making a single-article.php file, but it is still using the single.php template page. Based on the documentation it should work. What could I've done wrong?
2 Answers
If you want to change the single page
page-{page-slug}
is a good choice if you want the page template for specific page only and not multiple pages.
Check out his custom page template for specific page
If you are talking about custom post type
We can use single-$posttype.php
, here $posttype
is your custom post type slug.
WordPress template Hierarchy for single post page's custom post is in the order of :
single-$posttype.php ==> single.php ==> singular.php(WP 4.3+)
So if a custom post single page is requested, WP first looks for single-$posttype
file if it's available it uses that file else it goes to single.php
and so on as the above order.
Refer to Template Hierarchy for more details.
-
the custom page is named article.php ,and i tried single-article.php with no succes. The pages are already created though and they dont change even though the single-article.php is totally different then single.php– cynenJun 9, 2016 at 10:32
-
It's more than 1 page, i need to change the template of all the custom post pages.– cynenJun 9, 2016 at 11:35
-
-
In the wordpress backoffice , i have a tab (i think thats called a custom post) where i can create pages . I also have a webpage on the website which loops through these custom post pages. And if you click on one of the pages , the "single.php" page is showed. Instead of the "single.php" i want the "single-article.php" page to be shown.– cynenJun 9, 2016 at 11:59
Assuming that you are talking about a custom post type the answer is right in the codex. Generate a template called single-{post-type}.php
and WP takes care of the rest.
-
he custom page is named article.php ,and i tried single-article.php with no succes. The pages are already created though and they dont change even though the single-article.php is totally different then single.php– cynenJun 9, 2016 at 10:33
article.php
a page template ?