Forums

Grouping child categories by description for conditional content display (3 posts)

  1. dezarii
    Member
    Posted 8 months ago #

    I'm working on a site about jobs in different cities. For each city, there are several types of job. I've listed each city as a parent category and each job as a child category. The job descriptions are exactly the same for each city. Something like:

    New York
    - dentistsNY (description: "Dentists")
    - floristsLA (description: "Florists")
    Los Angeles
    - dentistsLA (description: "Dentists")
    - floristsLA (description: "Florists")

    For navigation, you can choose a city from a dropdown list and the child categories (jobs) for that city are listed by description, so the navigation looks the same on every page even though the links are different.

    Now I want to display special header images across every job type page, like this:

    if child category description = Florists
    then display florists.jpg

    If child category description = Dentists
    then display dentists.jpg

    So in this example, all Florists child categories of each city would show the same image header.

    The Codex lists conditional options for slugs and names, but that won't work here because those have to be unique. Or can you use slugs based on their containing a specific word as part of the full slug?

    Alternatively, is there another way to group child categories independently of their parent categories so that each group could display certain images, widgets, etc?

    Ultimately this site will have many categories, so I don't want to have to specify them by number each time I add more.

    Any help would be appreciated!

  2. stvwlf
    Member
    Posted 8 months ago #

    Hi

    The WP category system is hierarchical, and sub-categories under one branch can not be subcategories under another branch. In other words, in the structure you are proposing, there is no relationship between LA florists and NY florists, even though florists appear to be the same category. To say it another say, a subcategory can only have one parent.

    A post can be assigned to more than one category... Would it work if you had one parent category for City and another for Job? NY and LA would be child categories of City, and florist and dentist would be child categories of Job. When you want all dentist jobs in NY you would query for posts assigned to both of those categories.

    That way, all dentists everywhere would be in the same dentist category. Thus it would be easy to know if a dentist page header was supposed to display. You can still display only dentists in NY on that screen by querying for both of those categories.

  3. dezarii
    Member
    Posted 8 months ago #

    Thanks, I think that would work. I knew they could be assigned to more than one category, but for some reason that solution just slipped by me. I really appreciate your taking the time to help!

Reply

You must log in to post.

About this Topic