I have a page template in WordPress that allows new pages to be created to display and explain treatment details. E.g.

  • Chiropractor Page
  • Acupuncture Page

When a new treatment page is created from the template, it is required to put which clinics provide the treatment in the sidebar. The clinics listed will vary for most treatment pages so this information cannot be hard-coded.

I'm unsure on how I should be doing this?

I have a unique sidebar that the template uses but I'm not sure how I incorporate this dynamic functionality into that sidebar?

I guess it would make most sense that when I create the page within WordPress, there is something like the 'Featured Image' option where I can drop this information in.

All help is greatly appreciated.



Add a custom taxonomy if you don't need to store much additional information. It's the easiest way to get a set of labels that you can assign to page.

Here's the basic method for using a custom taxonomy based on this codex page:


add_action( 'init', 'create_clinic_tax' );

function create_clinic_tax() {
       'page', // post type to register the taxonomy with
          'label' => __( 'Clinic' ),
          'rewrite' => array( 'slug' => 'clinic' ),
          'hierarchical' => true

With this code in your functions.php you'll get a box like the category box in your edit screen sidebar. You can add the clinic names or choose from existing ones there.

Displaying the clinics in your sidebar would be like this:

With links:

if ( is_page() ) {
    echo '<ul class="clinics">';
    the_terms( get_the_ID(), 'clinic', '<li>', '', '</li>' );
    echo '</ul>';

Without links:

if ( is_page() ) {
    $clinics = get_the_terms( get_the_ID(), 'clinic' );
    if ( $clinics ) {
        echo '<ul class="clinics">';
        foreach( $clinics as $clinic ) {
            echo "<li>{$clinic->name}</li>";
        echo '</ul>';
    } else {
        // no clinics assigned

If you use the option to display clinics as links when visitors click on them they will see an archive page listing the treatments associated with that clinic. Could be handy.

You can use the Advanced custom fields plugin to add extra fields to your clinics too that you could display on the clinic archive pages.


If the clinics need more metadata and a reliable permalink you might be better off with a custom post type and using the advanced custom fields plugin to add a field for choosing the relevant clinics.

To register a post type look at the codex page for register_post_type():


| improve this answer | |
  • Thanks so much for your reply sanchothefat, this is very useful but I do have some questions. 1) When I register the taxonomy, is there a way to restrict the pages in which this option shows up in the edit page sidebar? Currently it shows on all pages but this is not required. 2) I have 3 existing clinic pages, and at the moment I am just using the default permalinks. Is there a way to hardcode the link rather then using the one that is currently being generated? E.g. Maidenhead would be 'localhost:81/?page_id=42' Thanks again – Johnny Feb 26 '13 at 18:29
  • Hardcoding links isn't the best idea but to change the default URL structure you need to go to the Permalink settings page in admin and select one of the pretty permalink structures. That will give you URLs like /page-name/ etc... At that point you can edit the page 'slug' by clicking the yellow bit of the page URL displayed under the page title edit field. – sanchothefat Feb 26 '13 at 20:13
  • @Johnny Sorry, there also isn't a nice way of hiding the taxonomy from certain pages. Maybe if they had a specific page template. Same is true for just using the ACF plugin mentioned and displaying fields based on page template selected. – sanchothefat Feb 26 '13 at 20:16

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.