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 have a page "Portfolio", it contains a loop that outputs the list of portfolio (Custom Post Type, is this the problem?) items using page-portfolio.php. Problem is somehow WordPress used the archive.php to render my portfolio page, why is that?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

An archive of a custom post type is displayed using archive-[posttype].php or archive.php if the first does not exist (see the Template Hierarchy for the full details). page-[posttype].php is only used if you create a "dummy" page to show a custom post type archive (before WordPress 3.1).

So in your case you should rename page-portfolio.php to archive-portfolio.php, and don't include a header to indicate a page template name.

share|improve this answer
add comment

I don't think it is possible to use portfolio.php for the Custom Post Type "Portfolio".

The way I have solved it on a site I did recently was to call my Custom Post Type "Project" instead. Then pull the content in via a Page Template called portfolio.php (see Brady's answer). Then to show the single Projects, I use a template called single-project.php

share|improve this answer
    
Was this before custom post type archives were introduced in WordPress 3.1? –  Jan Fabry Apr 18 '11 at 11:35
    
Well Jan, I am not really sure as I have it working this way on 3.0, 3.1 and 3.1.1 –  Piet Apr 18 '11 at 16:07
add comment

Make sure you have added the comment block to your page-portfolio.php to tell its a template.

Add this to the top of the file:

<?php
/*
Template Name: A Template Name of Your Choice
*/
?>

Go into pages in the admin area of WordPress and create a page and assign the above template to that page.

share|improve this answer
add comment

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.