I have registered a custom post type and I want to create a page where I will list some posts, it will be like an index page.
I have created an archive page called mycpt-archive.php and a page called myCPT.php.
I’ve added a custom URL in the menu called “myCPT” like this : www.mywebsite.com/mycpt
Now, when I click from the front-end menu on “myCPT” it displays the mycpt-archive.php content and not the myCPT.php.
I’ve looked through the template hierarchy from CODEX and it seems I’m on the right track.
When I click on “myCPT” from the front-end menu the page displayed is mycpt-archive.php not myCPT.php which I’m expecting to open.
What am I missing here ?
Thank you !
If you have:
register_post_type( 'my_custom_post_type', $args );
And you need a custom page to displays all entries from this custom post type, you have to create:
archive-my_custom_post_type.php
.But if you don’t need a custom page, wordpress will use archive.php to display you custom post type archive.
If you only need to customize the entry page, you have to create:
single-my_custom_post_type.php
Where are you creating the custom post type, in theme functions.php or using a plugin?
If using functions.php, you need to create
archive-my_custom_post_type.php
orsingle-my_custom_post_type.php
in theme’s folder.If using a plugin, you need to create
archive-my_custom_post_type.php
orsingle-my_custom_post_type.php
in plugins’s folder and point wordpress to read it, so include this function in your plugin:It almost sounds like you would create a custom template page named whatever and put the custom query code you want into that particular template page. Once you make the template page, create an actual wordpress page and set it to use that custom template page. Does that make sense.
Once you are done, you will probably want to edit the template page to tweak and refine your query.
Let me know if I’m on the right track for your needs.