1

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?

5
  • Do you mean custom post type?
    – bravokeyl
    Jun 9, 2016 at 10:21
  • Is article.php a page template ?
    – bravokeyl
    Jun 9, 2016 at 10:34
  • Aparently both @bravokeyl and I are confused about what you mean. Perhaps you should refrase your question to explain your problem more clearly.
    – cjbj
    Jun 9, 2016 at 10:45
  • I tried describing it as clear as possible.
    – cynen
    Jun 9, 2016 at 11:50
  • Could you post the code of article.php?
    – cjbj
    Jun 9, 2016 at 12:30

2 Answers 2

2

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.

4
  • 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
    – cynen
    Jun 9, 2016 at 10:32
  • It's more than 1 page, i need to change the template of all the custom post pages.
    – cynen
    Jun 9, 2016 at 11:35
  • @cynen , when you say custom post pages ,what exactly do you mean?
    – bravokeyl
    Jun 9, 2016 at 11:37
  • 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.
    – cynen
    Jun 9, 2016 at 11:59
1

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.

1
  • 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
    – cynen
    Jun 9, 2016 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.