• Resolved gmalone

    (@gmalone)


    Hi David, how do WordPress site devs manage without MLA? ??

    Question:
    How do I display the number (quantity) of child att categories under a given parent?
    I don’t mean “display number of images, etc”. I know how to list the categories, etc.
    I need to be able to display a simple number that represents the number of child att categories under a specified parent att category.

    Example:
    parent = animals
    children = cats, dogs
    number of children of animals = 2 <—–

    Thanks for the assist. I’ve searched this forum up and down many times for an answer, so finally am posting.

    • This topic was modified 3 years, 11 months ago by gmalone.
    • This topic was modified 3 years, 11 months ago by gmalone.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for the positive feedback regarding MLA and for your interesting question.

    Because of the way the WordPress database is organized computing the number of child terms is a bit of a challenge. However, it should be feasible to do it in the context of the processing done for the [mla_term_list] shortcode. You want to “display a simple number“. Can you give me more details about where and how you’d like the number to appear? For example, do you want to include the number in the list generated by the shortcode or do you want the shortcode to simply return an integer value or an array of terms and counts or something else?

    Any additional details you can provide will be helpful. I will investigate further and post an update here when I have progress to report. Thanks for your interest in the plugin.

    Thread Starter gmalone

    (@gmalone)

    Thanks David. Here’s what I’m hoping for:

    First, I have an Att Category called birds.
    Beneath it I have dozens of child categories, one for each species of bird.

    My wish is to be able to output something like this:

    “Current number of bird species: 54”
    … where 54 is the ‘count’ of subcats under ‘birds’ cat

    If the number has to occupy a separate line, no problem. Inline, tho, would be sweet.

    The following presumes using either a ‘count’ query, or you iterate a temporary counter on your end.

    Perhaps a simple (hah!) string constructor might be a solution:
    [mla_term_list count att_category=birds] outputs an integer number by itself

    or perhaps a bit more involved:
    [mla_term_list count att_category=birds prefix=”Current number of birds: “]

    and if you wanted to provide a flexible sentence constructor:
    [mla_term_list count att_category=birds prefix=”Current number of birds: ” suffix=”!”]

    Anyway, your kind consideration is appreciated. Just brainstorming w/ you. ??

    Greg

    Plugin Author David Lingren

    (@dglingren)

    Thank you for your comments and for your patience while I pondered this idea.

    You can accomplish your goal by defining a custom markup template for the [mla_term_list] shortcode and then using some of the existing parameters to filter the display down to a single element. Here is an outline of the approach you can adapt as you need.

    First, define a custom markup template:

    1. Navigate to the Settings/Media Library Assistant Shortcodes tab
    2. Click “Add New Template”
    3. Select template type “Markup”
    4. Select template shortcode “Term List”
    5. Enter something like “term-count” in the Name section
    6. Enter a Description if you like, e.g., “Display the padded count of child terms.”
    7. Fill the template sections with the values below
    8. Scroll to the bottom of the page and click “Update” to save the template

    Here are the section values (leave the other sections blank/empty):
    Open
    <span>

    Item
    Current number of [+name+]: [+count+]

    Close
    </span>

    You can adapt the content of the “Item” section to suit your needs.

    Once that’s done you can add a mla_markup=term-count parameter to your [mla_term_list] shortcode(s) to use the new template. For example:

    [mla_term_list taxonomy=attachment_category mla_style=none mla_markup=term-count include_tree=34 pad_counts=true]
    

    In the above example “34” is the term ID of the “birds” term. You can find the term ID by going to the Media/Att. Categories screen, hovering over (or clicking on) the “Edit” link under “Birds” in the Name column and finding the “tag_ID=” value.

    I hope that gets you started on a solution for your application. I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above suggestions.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to display the number of child att categories?’ is closed to new replies.