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 1
Add a comment  | 

1 Answer 1

Reset to default 1

there 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