如果is_single,Wordpress条件 [英] Wordpress Conditional if is_single
问题描述
我试图在我的single.php页面上使用条件语句。
Im trying to use a conditional statement on my single.php page.
我想做的是,如果它是Custom Post Type当前产品,使用特定的单一产品.php模板页面,如果没有(即标准博客文章)使用默认的single.php页面。
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...?
推荐答案
WordPress会自动为不同的帖子类型使用不同的模板页面,如果您的帖子类型被称为产品,则应该命名文件单products.php。您可以从那里阅读更多相关信息 Codex
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
同样,单个帖子及其档案可以分别使用single.php和archive.php模板文件显示,
In the same way single posts and their archives can be displayed using the single.php and archive.php template files, respectively,
- 自定义帖子类型的单个帖子将使用single-{post_type} .php
- ,他们的档案将使用archive- { post_type} .php
其中{post_type}是register_post_type()函数的$ post_type参数。
where {post_type} is the $post_type argument of the register_post_type() function.
这篇关于如果is_single,Wordpress条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!