Category Templates with Cascading Power

  1. Haluk_Karamete

    Here is how I see it as high-level...

    User clicks on "add a category" on the WP admin UI. in addition to the current stuff, he now gets a "category template" drop down - where he can define the category template plus a checkbox to help-manage cascading.

    Sample Category Template DropDown Contents

    As to the checkbox..

    The new UI should also have a check box labeled as "apply this template to sub categories" and that checkbox should be checked by default!

    You guys can figure it out as to how to populate that drop down, and what conventions to use in cat templates to show up in that drop down but that's beside the main point I want to address here.

    I am very big about that checkbox for "apply this to sub categories" thing. It's all about convenience.

    Imagine where you have to deal with a situation,  where an entire top level category tree has to share some common layout/style settings downward.

    With this feature, you not only could assign what template that top level cat to use but also (thanks to that checkbox), could enforce all the sub cats to default to that top level template. And this will cause you to literally "do nothing" for all the sub and sub-sub cats to follow/cascade downward.

    Say, you assign the category-red for the top level category titled as " CATEGORY RED". As you create sub and sub-sub cats for that top level, you basically do "nothing" about managing the sub categories' templates. Everything down from the top level "RED", will end up using the category-red layout!. And when you change that to say, category-dark-red, the entire sub tree involved will switch to category-dark-red in one setting. How wonderful is that!

    Ofcourse, this idea is not to take care of just the styles, colors etc... This color based example was only to make it easier to explain as to what cascading power can do here!

    If you guys are interested, we can take this core idea to the next level and iron out the issues!

    Posted: 5 years ago #
  2. Although this is good there are 2 fundimental issues:

    1) Categories are a Taxanomy and this would effect Tags etc too. As it would effect their database as well.

    2) We would need a place to store this information. Do we add a template or meta field to wp_terms or does this provide another uses case for Terms Meta.

    Posted: 5 years ago #
  3. Also for the SubCategories I think that the child should have the control as opposed to the parent controlling the children order of presidence a php template the belongs to the child > the selecting of theme chosen for the child > the parents theme > category.php > etc…

    Posted: 5 years ago #
  4. Haluk_Karamete

    Let's continue the discussion based on an example that is down to earth so it's easier to follow up on.

    Say the web site we are about to build have categories that deal with cities in the world, and we build a hierarchy based on country/state/city/region etc.

    In this case, the top level cats would be some country names such as

    united states, uk, germany...

    with that pre-set, we can build the category tree to be something like this;

    usa [a top level category ]
    --------los angeles
    ------------beverly hills
    ------------santa monica
    ----------------north hollywood
    --------san fransisco

    uk [another top level category ]

    germany [another top level category ]

    with the above example, you can select the template "category-us" from that category templates drop down to set it to be the template for the top level category USA! And while doing that, you can also check the checkbox for "apply this template to all sub cats"!

    with that, as you create subs and sub-subs for the US category tree, you will have three choices to exercise;
    1- do nothing
    this would cause the current sub will end up using the parent cat template.

    2- assign a template for the current sub cat and leave the checkbox off.
    this would use the selected template for the current sub - without effecting the sub levels that may come afterwards.

    3- and finally, assign a template and leave the checkbox on.
    And this would tell sub categories to follow to use this new category template downward.

    Let's take the california category as an example.

    Say, you just created "california" as a new sub category under the US category tree.

    one option is to do nothing. this would allow california to adopt the template from its parent and as a result california will end up working with the category-us template.

    But if you wish to force california to have its own template, you can select the category-ca template from the category template drop down.

    Now, the choice is yours...
    if you leave the check box as checked, then everything below will follow suit causing the subs such as "los angeles", "san francisco" even all the way down to "north hollywood" to have the category-ca template.

    But if you do not check the checkbox "apply this template to sub categories" option, then that change will only effect the california causing "los angeles", "san francisco", and "north hollywood" etc to still use the category-us.

    Does that answer your question?

    Posted: 5 years ago #
  5. I got that but I am thinking logically we should consider how it would work. In your example the "Term" California is a Term assigned to the taxonomy "Category" the issue lies that we need to save the selection. In order to save this data we would need to make a database change to the _term_taxonomy table or add term meta.

    Also hierarchical taxonomies share all their code with categories, and tags do to a big extent as well. From this respect it is not as simple as a check box to all effect all children because when loading a child the parent is not even considered, let alone grandparents. To this effect it would be easier to assume the parent or not support child categories.

    Posted: 5 years ago #
  6. Haluk_Karamete


    Can we not store this data in the wp_options table?

    Short of finding a better place, wp_options may take care of the data storage issue.


    option_name: wp_category_extended_meta_data_[category_id_here]
    option_value: {t:category_usa}{sc:1}

    here in the option_value, the "t" is used for taking care of the template name and the "sc" is used to keep track of "apply this to sub cats" TRUE/FALSE value.

    for every category and the sub and the sub sub category, you will have an wp_option record as follows;


    where 1,2,3 and 300 maps to category id's.

    At run time, when WP figures out that it needs to serve category id say 59, it will look up the wp_options table and query it for wp_category_extended_meta_data_59 and that will return what template to serve at that moment.

    Keeping this data available and being up-to-date would be the job of the same internal mechanisms which manage the categories.

    for example, when we add a new category, the routines which take care of adding the new category will make sure that a new wp_options record gets added into the wp_options_table with the newly created category id and its associated data as to what the t and sc value is.

    A recursive update can take care of the cascading data to be kept updated at all times so that run time queries are fast.

    Posted: 5 years ago #
  7. Justin Tadlock
    WordPress God

    This topic has already been posted here:

    In it, you can find more answers about using wp_options and why we need a wp_termmeta table (or something similar).

    Posted: 5 years ago #

RSS feed for this topic


You must log in to post.

  • Rating

    0 Votes
  • Status

    Duplicate of another idea