Page template with custom query instead of archive-xxx.php?

I have created a custom post type and I would like to list the posts. I have choosen a page template with a custom query instead of archive-xy.php to list the posts because the user would like to edit the content on the page. The custom query works, but if I create a page with slug XY and I open the page, the template is not working, I only see the the default layout (index.php). I’ve renamed it to for example to xy-2 and it works.

Is it possible to disable the domain.com/xy, because it’s using the blog layout? (because no archive-xy.php).

Answer

I had a similar problem going on. I had a custom post type Vacatures which I wanted to display with a page-vacatures.php.

But the layout was completely messed up. After digging through every file in my theme, I figured out that the webpage used archive.php.

Setting 'has_archive'=>false solved my problem because WordPress wouldn’t search for an archive file but for the template file (page-vacatures.php) that I specified.

@Rinoleti: Have you tried saving your permalinks again? After changes to a link I always save the permalinks again because WordPress can do weird stuff after changing a slug or something like it.

Attribution
Source : Link , Question Author : Rinoleti , Answer Author : Yerlix

Leave a Comment