1

I am currently building a site for a local day spa and I have hit a dead end in regards to the treatments page. I just don't know what I'm doing, I have been stuck on this problem for a couple of weeks now. Being a newbie to WordPress Theme Development, I'm really struggling with this as I'm not 100% sure of the best method.

This is the layout I'm looking to have:

- Treatment Category (Waxing)
    - Treatments Within That Category (Half Leg Wax, Full Leg Wax, etc)

I have managed to create a custom post type and taxonomy (assuming this is what I need to do) and I have been successful in create treatment categories and the treatments themselves, but I'm just stuck on how to actually output these to a page.

Here's the code I have used to create the custom post type and taxonomy:

functions.php

function lds_treatment_cpt() {
   $labels = array(
      'name'                =>  _x( 'Treatment', 'post type general name' ),
      'singular_name'       =>  _x( 'Treatment', 'post type singular name' ),
      'add_new'             =>  _x( 'Add New', 'Treatment' ),
      'add_new_item'        =>  __( 'Add New Treatment' ),
      'edit_item'           =>  __( 'Edit Treatment' ),
      'new_item'            =>  __( 'New Treatment' ),
      'all_items'           =>  __( 'All Treatments' ),
      'view_item'           =>  __( 'View Treatment' ),
      'search_items'        =>  __( 'Search Treatments' ),
      'not_found'           =>  __( 'No Treatments Found' ),
      'not_found_in_trash'  =>  __( 'No Treatments Found in Trash' ),
      'parent_item_colon'   =>  '',
      'menu_name'           =>  'Treatments'
   );

   $supports = array(
      'title',
      'editor',
      'author',
      'custom-fields',
      'post-formats',
      'comments',
      'revisions'
   );

   $details = array(
      'labels'          =>  $labels,
      'description'     =>  'Everything you want to know about a treatment',
      'public'          =>  true,
      'menu_position'   =>  5,
      'supports'        =>  $supports,
      'has_archive'     =>  true,
   );
   register_post_type( 'treatment', $details );

}
add_action( 'init', 'lds_treatment_cpt' );


function lds_treatment_taxonomy() {
   $labels = array(
      'name'                =>  _x( 'Treatment Categories', 'taxonomy general name' ),
      'singular_name'       =>  _x( 'Treatment Category', 'taxonomy singular name' ),
      'search_items'        =>  __( 'Search Treatment Categories' ),
      'all_items'           =>  __( 'All Treatment Categories' ),
      'parent_item'         =>  __( 'Parent Treatment Category' ),
      'parent_item_colon'   =>  __( 'Parent Treatment Category:' ),
      'edit_item'           =>  __( 'Edit Treatment Category' ),
      'update_item'         =>  __( 'Update Treatment Category' ),
      'add_new_item'        =>  __( 'Add New Treatment Category' ),
      'new_item_name'       =>  __( 'New Treatment Category' ),
      'menu_name'           =>  __( 'Treatment Categories' ),
    );

    $args = array(
      'labels'          =>  $labels,
      'hierarchical'    =>  true,
    );

    register_taxonomy( 'treatment_category', 'treatment', $args );
}
add_action( 'init', 'lds_treatment_taxonomy', 0 );

In a nut shell I need to know how I can output all the treatment categories on to once page and then display the treatments within a particular category on another page (if that makes sense).

I would really appreciate some help with this as I've been stuck on it for way too long.

Thanks

Stu :)

0
0

As @N00b pointed out this can go in many answers and needs many concepts digestion.I will try to concise and give a sample answer with little info.

Since you have set has_archive to true while registering post type , we can see all treatment post-type post on example.com/treatment/. If we want to change this page to display just taxonomy categories list, we can use template page for this.

Create archive-treatment.php in the root directory of the theme (If you know how to code and create child themes or the theme is your own ). Example archive-treament.php looks like.

archive-treatment.php

<?php
    get_header();
    $args = array(
        'show_option_none'    => __( 'No treatment categories' ),
        'style'               => 'list',
        'taxonomy'            => 'treatment_category',
        'title_li'            => __( 'Treatment Categories' )
    );
    wp_list_categories($args);
    get_footer();

Here wp_list_categories outputs the categories available in the treatment_category taxonomy and check all the arguments available.

If you just want to create page and use shortcodes there are many plugins out there that do this.

Reference:

Template Hierarchy

wp_list_categories

Display Posts Shortcode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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