Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 like http://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 like http://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.

share|improve this question
    
This is something that I'm converting from a static .html site into WordPress. You can see how the .html site is currently working and what I'm trying to replicate here: patiodepot-inc.com/AreasWeService/State-NORTHERN_CALIFORNIA –  NW Tech Jan 10 '13 at 19:44
1  
it's a bit difficult to see exactly what you're trying to replicate- all of the pages that aren't just lists of links seem identical in their content, and the detailed services links all 404. what is a local page exactly? how do you associate a service to a location if locations are just another taxonomy, and not actual post objects? –  Milo Jan 14 '13 at 17:41
    
Do you have update the permalink settings, that the nice url works also on your custom post type? –  bueltge Jan 14 '13 at 21:29
    
@Milo My client asked me to take that html site (which has tons of broken links) and put it into WordPress and make it work. Page creation/editing is much simpler in WordPress, than editing each of those pages in Dreamweaver or whatever is used. If there's a better way of associating locations to a post besides a taxonomy, I'm all ears. It's the only thing I could think of that would allow the post to be assigned multiple services and locations. And this is where it got convoluted for me in creating the directories/archives of the taxonomies. –  NW Tech Jan 14 '13 at 22:42
3  
You have the rewrite post type argument set to false. Removing this line should give you pretty permalinks. –  bungeshea Jan 15 '13 at 6:39

1 Answer 1

up vote 1 down vote accepted
+50

To achieve permalinks like http://example.com/localpage/%post_name%/, you will need to set the rewrite argument when registering the custom post type:

$annoucement_args = array(
    ...
    'rewrite' => array( 'with_front' => false ),
    ...
);

I don't think that using custom taxonomies is the best idea here. Why not use custom meta boxes instead? See this WP Explorer article for guidance.

share|improve this answer
    
If I were to use custom fields and create a multiple selection checkbox field, could I then create a page that lists all of those terms with something similar to get_term_by? –  NW Tech Jan 16 '13 at 22:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.