0

I'm making a directory for half a dozen sorts of venues that are located in innumerable cities in all 50 US states. My plan has been to use a custom post type for each venue type and then assign a hierarchical "location" taxonomy to all of them.

When I create my "location" taxonomy archives, I'd like to start plugging in information about each state and eventually each major city. I envision an article about the location, a list of related tags and categories about what could be found in that location, and some excerpts from blog posts. Once you click through to a venue type, you'd get a list of that sort of venue in the "location."

How can I dynamically add an article about that location to the top of a location taxonomy's archives?

Or, should I have gone with a "location" custom post type instead? However... that would still give me a location-related taxonomy archive that does not begin with an article about the location.

3 Answers 3

1

I am not sure off-hand if custom taxonomies have this (I'm almost positive they do) but Tags and Categories already have a Description field you can fill out, and then display on any page. It would take some modification of your template files but what you can do is something like this:

  1. Enter the description in the appropriate field
  2. Use this code to display it on archive.php or whatever controls your archive pages:

    $termdesc = term_description( $term_id, 'location' /* or taxonomy name */ );
    if( $termdesc != '' )
        echo $termdesc;
    

Code above is using term_description.

2
  • you're right, taxonomies can have an entry field for a description, just like blog tags and categories - a little tiny entry field. I want to be able to insert more information, say a paragraph about the area's history plus a list of seasonal cultural events and a joke about the weather. If it wasn't a big site I could hard code it. Is there a way to stop the description field from messing with my html? If so, it would not matter that the field is tiny. ;-). It would be neat if, instead of html, I could drop in a link into the description field and have it become an include. Commented Feb 12, 2012 at 19:54
  • The HTML in the description field may be escaped but in that case you could do something like: echo html_entity_decode( $termdesc ); and it should render the HTML fine.
    – Jared
    Commented Feb 13, 2012 at 1:21
1

Just make a taxonomy template and customize it with whatever you want.

The WordPress hierarchy for taxonomies flows like this.

archive.php ---> taxonomy-$taxonomy-$term.php --> taxonomy-$taxonomy.php --> taxonomy.php

So you can make a template called taxonomy-location.php

http://codex.wordpress.org/Template_Hierarchy

3
  • I already have a taxonomy named location. When users go to an archive for a location, I want to be able to top that archive with an article about the location. Commented Feb 12, 2012 at 19:02
  • Also, I could have 500-1000 of these locations to write descriptions for. Let's say I have 3,000 community theaters, restaurants and churches that are spread around in 500 locations, and I want each location's archive to have a description of whatever city or state it happens to be. I don't know how to dynamically tell taxonomy-location.php to load the appropriate article to put at the top of each location archive. Is there a way? Commented Feb 12, 2012 at 20:06
  • Use WP Query with term_description
    – Wyck
    Commented Feb 12, 2012 at 22:01
0

You can use both location taxonomy and a location post-type. That way you can put much more information about the location e.g post-thumbnail or custom-fields and have it loaded on every location taxonomy query.

  1. Register the location post-type e.g location-post
  2. Add a location-post for every location-term you made
  3. On the location-post add a custom-fields that relates to the location-term ID e.g 'location-term'(key) = '12'(value=the location-term ID).
  4. If you already using taxonomy-location.php, you can use a get_post query with a meta_key parameter to call the location-post right before the loop.

Hope this help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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