Remo Web
Remo Web

Reputation: 63

Wordpress Conditional if is_single

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...?

Upvotes: 3

Views: 12463

Answers (3)

Jodyshop
Jodyshop

Reputation: 664

I believe if you want to use for posts try this:

is_singular('post');

Thanks

Upvotes: 0

MrHunter
MrHunter

Reputation: 1900

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.

Upvotes: 1

Dharmang
Dharmang

Reputation: 3028

You can use is_singular() function, according to WordPress documentation: Ref Link

This conditional tag checks if a singular post is being displayed, which is the case when one of the following returns true: is_single(), is_page() or is_attachment(). If the $post_types parameter is specified, the function will additionally check if the query is for one of the post types specified.

True when viewing a post of the Custom Post Type book.

is_singular('book');

This will accomplish your task.

Upvotes: 1

Related Questions