WordPress.org

Ready to get started?Download WordPress

Forums

Multiple taxonomies - A more elegant solution? (3 posts)

  1. Pan Fried Pixels
    Member
    Posted 1 year ago #

    Hi guys,

    I am listing taxonomy terms belonging to a post, only if they exist. So for each taxonomy I am repeating the code below, swapping out the first line as I go. As I have 5 or 6 taxonomies, doing this seems slightly verbose! I am wondering if anyone knows of a more elegant solution?

    Cheers.

    http://pastebin.com/MXrjYWiv

  2. bcworkz
    Member
    Posted 1 year ago #

    Create an array like so:
    $taxonomies = array('film','actor','director',//etc...);

    Then wrap your code in a foreach loop:

    foreach($taxonomies as $taxonomy) {
      //your code here
    }

    You'll also need to do some string manipulation so the h3 title is mixed case and plural. Echo out the result in PHP instead of hard coding the HTML string.

  3. Pan Fried Pixels
    Member
    Posted 1 year ago #

    Perfect. Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic