0

I'm currently building a site for a local beauty salon and I have come across an issue that I just cannot seem to put my finger on and I have been stuck on this for weeks, where I'm stuck is with the treatments page.

The project requires that I have a treatments page that lists all available treatment categories (massage, waxing, nails, etc). When a user clicks on the treatment category they're after they are then taken to another page that lists all the treatments within that category i.e., Treatments -> Waxing -> Full Leg Wax.

I did a Google search to try and find a good example of what I'm after and I came up with this example and it is exactly what I'm after.

Hierarchy

  • List of Treatment Categories (URL: site.com/treatments)
    • Individual Treatments (URL: site.com/treatments/waxing)
      • Individual Treatment Details (URL: site.com/treatments/waxing/back-wax)

I have used a custom post type for the individual treatments, named 'treatments', and then I created a taxonomy called ‘treatment-categories’ (I’ve used the slug names of each). I have used my archive.php template and obviously I have named this archive-treatments.php (code below). I will look at altering the layout of the template once I have this figured out.

<?php get_header(); ?>

<section class="hero hero-sml hero-default no-marg-bottom">
    <div class="container clearfix">
        <h1>
            <?php
                the_archive_title( '<h1>', '</h1>' );
            ?>
        </h1>
    </div><!-- .container -->
</section><!-- .hero -->

<div class="muted-bg">
    <section class="margin-top container clearfix">
        <div class="row">

            <?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>

            <div class="col-4 post-excerpt">
               <article>

                   <a href="<?php the_permalink(); ?>">
                       <?php
                           // Display the featured image
                           if( the_post_thumbnail() ) :
                       the_post_thumbnail( 'small' );
                    endif;
                 ?>
              </a>

              <time class="post-date">
                 <?php the_date(); ?>
              </time>

              <h3>
                 <a href="<?php the_permalink(); ?>">
                    <?php the_title(); ?>
                 </a>
              </h3>

              <p>
                 <?php the_excerpt(); ?>
              </p>

           </article>
        </div><!-- .post-excerpt -->

     <?php endwhile; endif; ?>

  </div><!-- .row -->

I have done the same for the treatment-categories taxonomy (archive-treatment-categories), is this the correct way of doing this? Is WordPress even capable of doing something like this? Also just to clarify in case this maybe an issue, I have a blog that utilises categories, tags, etc and a WooCommerce store if that helps.

I really appreciate any help with this, and I'm sure it's one of those solutions where I'll be saying "really, is that all I had to do?". I have been trying this for way too long and it doesn't make any sense anymore to me, I just need another opinion on how to do this.

Thanking you all in advance

Stu :)

  • At first glance it looks like your template should list all of the posts within the category that you are trying to access. Is that not what you want? – Andy Macaulay-Brook Aug 13 '16 at 12:41
  • Hi Andy. Here's what currently happens. When I go to the treatment page I can see all of the individual treatments list (URL: site.com/treatments) but there is no treatment categories (Waxing, Massage, etc) and it's going to the archive-treatments.php. Should I be utilizing a taxonomy or category template? Here's the URL I see site.com/treatments/half-leg-wax but it should be site.com/treatments/waxing/half-leg-wax/ Bit of a newbie with WordPress and I'm still trying to get my head around everything – stucow88 Aug 13 '16 at 14:58
  • To get your URLs like that, make sure your taxonomy is hierarchical and then set the parent of half-leg-wax to be treatments. As for showing them on the page, you'll need code for that in your template. I'll have a look at a proper answer with code when I'm back at a computer. – Andy Macaulay-Brook Aug 13 '16 at 15:37
0

I have been successful in achieving exactly what I was looking for. For me to solve this dilemma I used the following code in the archive-treatments template using the following code:

<?php
    $args = array( 'taxonomy' => 'treatment-categories' );
    $categories = wp_list_categories( $args);
?>

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.