WordPress – Allow dynamic text to be added into a sidebar upon page creation

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:

http://codex.wordpress.org/Function_Reference/register_taxonomy

add_action( 'init', 'create_clinic_tax' );

function create_clinic_tax() {
    register_taxonomy(
       'clinic',
       'page', // post type to register the taxonomy with
       array(
          '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.

http://www.advancedcustomfields.com/

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():

http://codex.wordpress.org/Function_Reference/register_post_type