How to make a custom "single.php" page for custom posts?


#1

Ok I have my portfolio custom post set up … and I created a custom template to show them so everything is ok for now.

But if I click on the post title, it lead to the single.php template … like my normal post do but I don’t want to … I want them to have their own single page …

How do I do that? :slight_smile:

Just for an exemple, on Classica : http://themes.premiumpixels.com/classica/portfolio/

If you click on the title of the portfolio post, it lead to a different page than blog post page.

Thanks!
Dany


#2

I think you only need to create a file called “single-posttypename.php” and style it to your needs.


#3

http://codex.wordpress.org/Post_Types has what you’re looking for

In the same way that posts are shown on their own page with single.php, custom post types will use single-{posttype}.php if it's available.

So for the above example, you could create a single-acme_product.php file and the product posts would be shown using that template.


#4

I think you can just create a template named single-portfolio.php (assuming your custom post type is portfolio). See this for more info: http://codex.wordpress.org/Template_Hierarchy#Single_Post_display

Hope that helps :slight_smile:

EDIT: That was some amazing response time, guys :stuck_out_tongue:


#5

Hey guys, I tried it already and it didnt seemed to worked. Will give it a second try and I’ll let you know if it worked.


#6

Oh! I’m stupid :slight_smile:

I wrote single-portfolioposts.php instead of single-portfolio_posts.php :slight_smile:

Thanks a lot guys!


#7

Great to hear Danny!
Related question, does this also work for the archives template?
For example “archive-portfolio_posts.php”?

EDIT: Sorry just checked in the codex and yes, it works the same way. :slight_smile:


#8
Bluz said

Great to hear Danny!
Related question, does this also work for the archives template?
For example “archive-portfolio_posts.php”?

Yes, with wp 3.1

The bad thing is that there is no way to easily link to a custom archive from the wp menu… the only way is to create a link manually: site.com/?post_type=slug

This to use the built in custom archives, I’m not talking about “page templates that act like custom post archives”.


#9

Source Digging Into WordPress blog


#10

@WPwpCanyonThemes

Great found! Thank you! I really searched for something like this! tytytyty!


#11
BroOf said

@WPwpCanyonThemes

Great found! Thank you! I really searched for something like this! tytytyty!

npnpnpnpnp. :slight_smile: