admin管理员组文章数量:1313249
I've created the custom post type (CPT) called 'projects':
$post_type_args = array(
//...
'has_archive' => true,
'rewrite' => array(
// 'slug' => '', // Defaults to $post_type key
// 'with_front' => true, // Default true
// 'feeds' => 'true', // Default has_archive value
// 'pages' => true, // Default true
// 'ep_mask' => EP_PERMALINK,
),
);
register_post_type( 'projects', $post_type_args );
And I would like the use a conditional tag only for the front page of the CPT.
In my case is the page with the slug /projects
.
I can use $_SERVER
array like this:
if ( $_SERVER['REQUEST_URI'] == "/projects/" ) { //... }
But is there something like is_shop()
conditional tag in WooCommerce for this case?
Thank you in advance.
I've created the custom post type (CPT) called 'projects':
$post_type_args = array(
//...
'has_archive' => true,
'rewrite' => array(
// 'slug' => '', // Defaults to $post_type key
// 'with_front' => true, // Default true
// 'feeds' => 'true', // Default has_archive value
// 'pages' => true, // Default true
// 'ep_mask' => EP_PERMALINK,
),
);
register_post_type( 'projects', $post_type_args );
And I would like the use a conditional tag only for the front page of the CPT.
In my case is the page with the slug /projects
.
I can use $_SERVER
array like this:
if ( $_SERVER['REQUEST_URI'] == "/projects/" ) { //... }
But is there something like is_shop()
conditional tag in WooCommerce for this case?
Thank you in advance.
Share Improve this question asked Dec 9, 2020 at 11:28 MaxMax 11 Answer
Reset to default 1there is an is_post_type_archive()
function https://developer.wordpress/reference/functions/is_post_type_archive/ that will tell you if you are on the https://example/projects/ page.
In your case you would need to use it like this
is_post_type_archive( "projects" );
since "projects" is your custom post type name.
本文标签: Conditional tag only for front of custom post type
版权声明:本文标题:Conditional tag only for front of custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741930152a2405528.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论