Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 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 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 at 19:01

1 Answer 1

up vote 1 down vote accepted

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.

share|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. –  Faisal79c2 Mar 19 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 at 18:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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