I've created a custom post type, Local Pages
and two different taxonomies: Locations
and Services
.
As of now, the custom post type works. However the urls are not pretty. They look something like: http://domain.com/?localpage=%post_name%
Ideally, I'd like to create an archive for the post type and the taxonomies.
For example, the main archive would be something like http://domain.com/localpage
, which would list all of the posts in that post type. I assume this would require it's own archive template.
I'd also like to create a category list page for my taxonomies, where the URL would be something like http://domain.com/localpage/locations
and http://domain.com/localpage/services
. Both of these pages would essentially list the all of categories or items of the particular taxonomy. Filter the links on each of those pages to the next taxonomy.
An example of how this would work would be:
Locations: Abbott, CA; Aberdeen, CA; Cable, CA; Strawberry, CA; Zuver, CA
Services: Aluminum Adjustable Patio Covers; Insulated Patio Covers; Store Front Awnings; Sunroom Enclosures.
When visiting
http://domain.com/localpage/locations
, you would see the above listed locations. Upon clicking on any particular location, you would then be sent to something likehttp://domain.com/localpage/%location_name%/services
where it would list all the services for that location. Upon clicking on a service, you would be taken to the post at something likehttp://domain.com/localpage/%location_name%/%service_name%/%post_name%
How might I accomplish this and what page template files (archive.php, single.php, etc) are needed?
Here's the code I'm using in my 'functions.php' to create the custom post type and taxonomies.
/////////////////////////////////////////////////
// Local Page Custom Post Type
/////////////////////////////////////////////////
function create_local_pages() {
$labels = array(
'name' => _x( 'Local Pages', 'post type general name' ), // Tip: _x('') is used for localization
'singular_name' => _x( 'Local Page', 'post type singular name' ),
'add_new' => _x( 'Add New', 'Local Page' ),
'add_new_item' => __( 'Add New Local Page' ),
'edit_item' => __( 'Edit Local Page' ),
'new_item' => __( 'New Local Page' ),
'view_item' => __( 'View Local Page' ),
'search_items' => __( 'Search Local Pages' ),
'not_found' => __( 'No Local Pages found' ),
'not_found_in_trash' => __( 'No Local Pages found in Trash' ),
'parent_item_colon' => ''
);
$annoucement_args = array(
'labels' =>$labels,
'singular_label' => __('Local Page'),
'public' => true,
'show_ui' => true,
'menu_position' => 5,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => false,
'supports' => array('title', 'editor'),
'has_archive' => true,
);
register_post_type('localpage', $annoucement_args);
}
add_action('init', 'create_local_pages');
/////////////////////////////////////////////////
// Local Page Taxonomies
/////////////////////////////////////////////////
add_action( 'init', 'build_locations', 0 );
function build_locations() {
register_taxonomy( 'location', 'localpage', array( 'hierarchical' => true, 'label' => 'Locations', 'query_var' => true, 'rewrite' => true ) );
}
add_action( 'init', 'build_services', 0 );
function build_services() {
register_taxonomy( 'services', 'localpage', array( 'hierarchical' => true, 'label' => 'Services', 'query_var' => true, 'rewrite' => true ) );
}
add_action( 'init', 'build_keywords', 0 );
function build_keywords() {
register_taxonomy( 'keyword', 'localpage', array( 'hierarchical' => true, 'label' => 'Keywords', 'query_var' => true, 'rewrite' => true ) );
}
Any help would be greatly appreciated.
Additional information
In the example provided, the local pages are pages within the site that relate to a geographic location and a single, particular service. Hence my reference to them as "local pages" for the custom post type. They could be named anything different for that sake.
From my understanding, this is an SEO play on his behalf. Most of the content is identical with the exception of some keyword and location changes throughout the content. Not something I'm real fond of, but I'm attempting to deliver what the client asked for.
rewrite
post type argument set tofalse
. Removing this line should give you pretty permalinks.