Skip to main content
deleted 1 characters in body
Source Link

Overview

I have a Custom Post Type called Locations. When the user visits **/locations**, I would like them to see some general information about all the locations. When the user visits **/location/{a-location}**, I would like them to see specific information about "a-location". Sounds easy enough.

1st Solution Attempt

I created a Locations page in the Wordpress dashboard to hold the content for the /locations url. I then created an archive-locations.php file and a single-location.php. archive-locations.php pulls info out of the Locations page and it lists all of the custom post type Locations. When the user clicks on a link for a location, the user gets redirected to /locations/{a-location} and single-location.php gets called. This almost does the trick, but it just doesn't feel right and it's creating some other problems.

The Problem

When a user visits /locations I would prefer to be working with a page template for the Locations page (instead of the archive-locations.php page). I'm using the Yoast plugin to specify a custom meta title and description for each page. Since archive-locations.php is being used, all of this meta gets ignored. If I were working with a page template, my meta info would get recognized correctly. Also, logically, it feels like I should be working on the Locations PAGE, not an archive. The Locations PAGE is it's own entity with much more content then just an archive of custom post types. To try and force it into an archive concept seems like a stretch.

2nd Solution Attempt

So I created a page-locations.php template for the Locations page and I was hoping that it would get called instead of the archive-locations.php. Unfortunately, it does not. I then tried removing the archive-locations.php thinking that maybe it was taking precedence. That didn't help either; Wordpress simply renders index.php. If I disable the Custom Post type and visit /locations, then my page template is called correctly. It looks like naming a custom post type the same name as a page causes Wordpress some issues. However, I need to be somewhat similar for the URL structures to work out. /locations needs to pull from a page template; /locations/{a-location} needs to pull from another php pfilefile.

Question

Is there any way to get page templates and custom post types with similar slugspermalinks to work together? If not, I guess my only option is to enhance my header.php and be smarter about determining the title and description when I'm on /locations.

Here's the code that registers my custom post type in case I'm doing something wrong:

$args = array(
    'labels'        => $labels,
    'description'   => 'Holds our location specific data',
    'public'        => true,
    'menu_position' => 20,
    'supports'      => array('title', 'editor', 'thumbnail', 'page-attributes' ),
    'hierarchical'  => true,
    'has_archive'   => true,
    'rewrite'       => array('with_front' => false, 'slug' => 'locations') //remove /news/ from the permalink when displaying a custom post type
);
register_post_type( 'locations', $args );

(I also tried changing has_archive to false, but it didn't help.)

Overview

I have a Custom Post Type called Locations. When the user visits **/locations**, I would like them to see some general information about all the locations. When the user visits **/location/{a-location}**, I would like them to see specific information about "a-location". Sounds easy enough.

1st Solution Attempt

I created a Locations page in the Wordpress dashboard to hold the content for the /locations url. I then created an archive-locations.php file and a single-location.php. archive-locations.php pulls info out of the Locations page and it lists all of the custom post type Locations. When the user clicks on a link for a location, the user gets redirected to /locations/{a-location} and single-location.php gets called. This almost does the trick, but it just doesn't feel right and it's creating some other problems.

The Problem

When a user visits /locations I would prefer to be working with a page template for the Locations page (instead of the archive-locations.php page). I'm using the Yoast plugin to specify a custom meta title and description for each page. Since archive-locations.php is being used, all of this meta gets ignored. If I were working with a page template, my meta info would get recognized correctly. Also, logically, it feels like I should be working on the Locations PAGE, not an archive. The Locations PAGE is it's own entity with much more content then just an archive of custom post types. To try and force it into an archive concept seems like a stretch.

2nd Solution Attempt

So I created a page-locations.php template for the Locations page and I was hoping that it would get called instead of the archive-locations.php. Unfortunately, it does not. I then tried removing the archive-locations.php thinking that maybe it was taking precedence. That didn't help either; Wordpress simply renders index.php. If I disable the Custom Post type and visit /locations, then my page template is called correctly. It looks like naming a custom post type the same name as a page causes Wordpress some issues. However, I need to be somewhat similar for the URL structures to work out. /locations needs to pull from a page template; /locations/{a-location} needs to pull from another php pfile.

Question

Is there any way to get page templates and custom post types with similar slugs to work together? If not, I guess my only option is to enhance my header.php and be smarter about determining the title and description when I'm on /locations.

Here's the code that registers my custom post type in case I'm doing something wrong:

$args = array(
    'labels'        => $labels,
    'description'   => 'Holds our location specific data',
    'public'        => true,
    'menu_position' => 20,
    'supports'      => array('title', 'editor', 'thumbnail', 'page-attributes' ),
    'hierarchical'  => true,
    'has_archive'   => true,
    'rewrite'       => array('with_front' => false, 'slug' => 'locations') //remove /news/ from the permalink when displaying a custom post type
);
register_post_type( 'locations', $args );

(I also tried changing has_archive to false, but it didn't help.)

Overview

I have a Custom Post Type called Locations. When the user visits **/locations**, I would like them to see some general information about all the locations. When the user visits **/location/{a-location}**, I would like them to see specific information about "a-location". Sounds easy enough.

1st Solution Attempt

I created a Locations page in the Wordpress dashboard to hold the content for the /locations url. I then created an archive-locations.php file and a single-location.php. archive-locations.php pulls info out of the Locations page and it lists all of the custom post type Locations. When the user clicks on a link for a location, the user gets redirected to /locations/{a-location} and single-location.php gets called. This almost does the trick, but it just doesn't feel right and it's creating some other problems.

The Problem

When a user visits /locations I would prefer to be working with a page template for the Locations page (instead of the archive-locations.php page). I'm using the Yoast plugin to specify a custom meta title and description for each page. Since archive-locations.php is being used, all of this meta gets ignored. If I were working with a page template, my meta info would get recognized correctly. Also, logically, it feels like I should be working on the Locations PAGE, not an archive. The Locations PAGE is it's own entity with much more content then just an archive of custom post types. To try and force it into an archive concept seems like a stretch.

2nd Solution Attempt

So I created a page-locations.php template for the Locations page and I was hoping that it would get called instead of the archive-locations.php. Unfortunately, it does not. I then tried removing the archive-locations.php thinking that maybe it was taking precedence. That didn't help either; Wordpress simply renders index.php. If I disable the Custom Post type and visit /locations, then my page template is called correctly. It looks like naming a custom post type the same name as a page causes Wordpress some issues. However, I need to be somewhat similar for the URL structures to work out. /locations needs to pull from a page template; /locations/{a-location} needs to pull from another php file.

Question

Is there any way to get page templates and custom post types with similar permalinks to work together? If not, I guess my only option is to enhance my header.php and be smarter about determining the title and description when I'm on /locations.

Here's the code that registers my custom post type in case I'm doing something wrong:

$args = array(
    'labels'        => $labels,
    'description'   => 'Holds our location specific data',
    'public'        => true,
    'menu_position' => 20,
    'supports'      => array('title', 'editor', 'thumbnail', 'page-attributes' ),
    'hierarchical'  => true,
    'has_archive'   => true,
    'rewrite'       => array('with_front' => false, 'slug' => 'locations') //remove /news/ from the permalink when displaying a custom post type
);
register_post_type( 'locations', $args );

(I also tried changing has_archive to false, but it didn't help.)

Source Link

Mixing Custom Post Types and Page Templates in Wordpress 3.7.1

Overview

I have a Custom Post Type called Locations. When the user visits **/locations**, I would like them to see some general information about all the locations. When the user visits **/location/{a-location}**, I would like them to see specific information about "a-location". Sounds easy enough.

1st Solution Attempt

I created a Locations page in the Wordpress dashboard to hold the content for the /locations url. I then created an archive-locations.php file and a single-location.php. archive-locations.php pulls info out of the Locations page and it lists all of the custom post type Locations. When the user clicks on a link for a location, the user gets redirected to /locations/{a-location} and single-location.php gets called. This almost does the trick, but it just doesn't feel right and it's creating some other problems.

The Problem

When a user visits /locations I would prefer to be working with a page template for the Locations page (instead of the archive-locations.php page). I'm using the Yoast plugin to specify a custom meta title and description for each page. Since archive-locations.php is being used, all of this meta gets ignored. If I were working with a page template, my meta info would get recognized correctly. Also, logically, it feels like I should be working on the Locations PAGE, not an archive. The Locations PAGE is it's own entity with much more content then just an archive of custom post types. To try and force it into an archive concept seems like a stretch.

2nd Solution Attempt

So I created a page-locations.php template for the Locations page and I was hoping that it would get called instead of the archive-locations.php. Unfortunately, it does not. I then tried removing the archive-locations.php thinking that maybe it was taking precedence. That didn't help either; Wordpress simply renders index.php. If I disable the Custom Post type and visit /locations, then my page template is called correctly. It looks like naming a custom post type the same name as a page causes Wordpress some issues. However, I need to be somewhat similar for the URL structures to work out. /locations needs to pull from a page template; /locations/{a-location} needs to pull from another php pfile.

Question

Is there any way to get page templates and custom post types with similar slugs to work together? If not, I guess my only option is to enhance my header.php and be smarter about determining the title and description when I'm on /locations.

Here's the code that registers my custom post type in case I'm doing something wrong:

$args = array(
    'labels'        => $labels,
    'description'   => 'Holds our location specific data',
    'public'        => true,
    'menu_position' => 20,
    'supports'      => array('title', 'editor', 'thumbnail', 'page-attributes' ),
    'hierarchical'  => true,
    'has_archive'   => true,
    'rewrite'       => array('with_front' => false, 'slug' => 'locations') //remove /news/ from the permalink when displaying a custom post type
);
register_post_type( 'locations', $args );

(I also tried changing has_archive to false, but it didn't help.)