Im trying to use a conditional statement on my single.php page.
What I want to do is, if it is of the Custom Post Type current-products, use a specific single -product.php template page, if not (ie a standard blog post) use the default single.php page.
I think Im using the right statement, but don’t know what to do afterwards (to get the template to be used):
if ( is_single( 'current-products' == get_post_type() ) { // If the post type is "Current Products" use this template... // Please help me out on this bit } elseif ( is_single() ) { // If not, use the standard one... // please help me out on this bit }
I think that’s right…?
Advertisement
Answer
WordPress automatically uses a different template page for different post types, if your post type is called products the files should be named single-products.php. You can read more about it from there Codex
In the same way single posts and their archives can be displayed using the single.php and archive.php template files, respectively,
- single posts of a custom post type will use single-{post_type}.php
- and their archives will use archive-{post_type}.php
where {post_type} is the $post_type argument of the register_post_type() function.