I've created a CPT named portfolio. Now i want to create a page which will act as an INDEX for this CPT. Now i've two choices ....

a) Make a custom template having custom WP_Query. In this way i can assign this template to any page and that page will work as an index.

b) Make archive-portfolio.php instead, which will act as an INDEX.

Now i've a few questions ...

1: Which is the correct approach?

2: If (a) then what is the actual usage of archive-cpt.php page then?

3: If (b) is correct approach, is there any possibility to make this page available in wordpress menu manager by default and also in the drop down menu (located at Setting->Reading) to use it as front page?

  • I feel it depends on how you want to display your content. If you plan on using a top to bottom "archive" format similar to that of a blog then I would use the archive template since it is clear what that template will be doing. On the otherhand, if have more of a page format that normal WordPress pages cannot handle or will take too much to customize ( think meta values, such as a members page ) then I would go with the cpt template. – Howdy_McGee Mar 19 '14 at 18:44
  • @Howdy_McGee I am tad confused about your comment, archive template and CPT template are same thing here - post type archive. :) – Rarst Mar 19 '14 at 18:50
  • CPT Template meaning choice (a) where he would have to create a template with a custom query where as the archive will get picked up automatically by WordPress - the CPT Template would have to be conditional if post type -> get_template() - I think this is better if you will not have a single.php tempalte. – Howdy_McGee Mar 19 '14 at 19:01

The correct way is latter one - correctly configure your CPT registration to have post type archive and use appropriate template file for it.

However it gets tricker with your additional requirements.

Exposing post type archives to be used in menus is significantly requested/explored topic, but I don't think it made it into core yet. There are mutiple solutions floating around, from quick search I have Post Type Archive Link plugin for it bookmarked.

Front page stuff is very convoluted. It's probably doable but unlikely to be smooth and will probably take some pre_get_posts tinkering and possibly overriding template hierarchy logic around there.

| improve this answer | |
  • 1
    Thnx for answering. I'm a building a theme for mass audience. Where these additional features are necessary and i don't think using any workaround in this case would be a good idea. So, i think i'll go with the first approach then. – Faisal Khurshid Mar 19 '14 at 18:56
  • @Faisal79c2 matter of opinion, but I highly doubt page approach is preferable for public release. It's just working around native archive functionality. There are also strong opinions around against having visible CPTs in themes altogether, since it locks user in. – Rarst Mar 19 '14 at 18:59

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.