Category listing of an object

291 views
Skip to first unread message

Franc Amour

unread,
Jul 24, 2016, 10:04:58 AM7/24/16
to Mura CMS
What would be the best way to list the categories that an object is associated with?  If I have a page that is in one or more categories, it would be nice to have them below the main content of the page, in a simple list.  Perhaps a custom component or plugin (preferred)?  What would be the best way to obtain the data for the list?

Gina S.

unread,
Jul 24, 2016, 7:10:47 PM7/24/16
to mura-cms-...@googlegroups.com
Thanks, Frank... that did the trick!  

On Sun, Jul 24, 2016 at 10:04 AM, Franc Amour <advan...@gmail.com> wrote:
What would be the best way to list the categories that an object is associated with?  If I have a page that is in one or more categories, it would be nice to have them below the main content of the page, in a simple list.  Perhaps a custom component or plugin (preferred)?  What would be the best way to obtain the data for the list?

--
You received this message because you are subscribed to the Google Groups "Mura CMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mura-cms-develo...@googlegroups.com.
To post to this group, send email to mura-cms-...@googlegroups.com.
Visit this group at https://groups.google.com/group/mura-cms-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/mura-cms-developers/ffd391ea-89a2-40ca-9129-431a43a53804%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Franc Amour

unread,
Jul 25, 2016, 9:45:14 AM7/25/16
to Mura CMS
??

Daniel Budde II

unread,
Jul 25, 2016, 12:01:56 PM7/25/16
to Mura CMS
Franc,

Is this something you want on every page, or just a specific type of page?  Depending on when and where you want to show the categories would determine for me what course of action I would prefer to take.

Daniel

Franc Amour

unread,
Jul 25, 2016, 12:58:31 PM7/25/16
to Mura CMS
it would be nice if it were another choice under "Navigation" in the Layout Manager - drag and drop into place, and whatever page/object being displayed, it would look up all the categories for that page/object.  Ultimately, a drop-in item when listing items (like a list of tags for a blog post) might be good too.  I think of a lot of cases where being able to show what categories an item belongs to could come in just as handy as a list of the tags.

Daniel Budde II

unread,
Jul 25, 2016, 2:30:53 PM7/25/16
to Mura CMS
I'm afraid I'm not following Franc.  It might be a difference between versions since I am on Mura 7, but I am not following what you are saying regarding the Nav and Layout Manager.

What I am asking is for more details of how you will decide what content gets the list of categories?  The reason I ask this is, if you want it on every page of the site, then you could just add it to the theme templates or you could make a component and add it to Home and have it cascade through the rest of the site.  If you want it only for specific content, then you could do it in a custom display object.  It just really depends what content you want it applied to and where you want it displayed.

Daniel

Franc Amour

unread,
Jul 25, 2016, 2:46:57 PM7/25/16
to Mura CMS
Example:

I have a folder, named FAQs.  Each page under FAQs represents an individual FAQ.  If a user ends up on an individual FAQ (by clicking it from the folder's listing, or from a web search, etc.), it would be nice to show the faq itself (title, body, etc) and below it have a list of all the categories to which is has been assigned, so that the user could go from an individual FAQ to clicking a category to see all the FAQs in that category.

Now, this could be accomplished by dragging and dropping an object using Layout Manager / inline editing, and it could be dragged and dropped either on each individual FAQ (PITA) or as an inheritable/cascading object from the FAQ folder object.  And each FAQ that appears in the folder listing could also have its categories listed, allowing for filtering while browsing the list.

That's the actual use case.  Built properly it could apply to pretty much any object that has been categorized.  Right now, if you look at any object in the system - i.e. viewing a page, or seeing a list of links, there's no way to tell what categories they belong to.

Daniel Budde II

unread,
Jul 25, 2016, 3:20:14 PM7/25/16
to Mura CMS
  • I think there is actually the ability to list categories a page belongs to already in Mura 7, but I'm not 100% on that and I don't think it accomplishes what you are looking to do anyway.
  • I do agree with you that you can create some sort of generic list feature for categories (such as it's own custom display object), but having a results page that works with the clicked category portion could be interesting for what you are wanting to do.  I have an idea on how I would do it, but I think you want the click to go back to your Folder/FAQ page, which means you won't want a generic solution.
  • Your options (there are a lot, but here are a few):
    • I agree with you, I wouldn't place the object on each and every FAQ page.
    • I think cascading from your Folder/FAQ page is a good option.  You should be able to create a custom display object just for your categories list and you should be able to get that to cascade.  This seems like your best option.
    • You could turn the pages into Page/FAQ class extensions and then create a custom display object for them that sets up the categories the way you want them to work.  Since you are looking for a more generic/reusable solution though, I would choose the cascade option.
Just my 2 cents.  Hope I'm helping.

Daniel

Franc Amour

unread,
Jul 25, 2016, 3:30:07 PM7/25/16
to Mura CMS
You are, and i appreciate it very much.  I'll mull it over!
Message has been deleted

Steve Withington

unread,
Jul 26, 2016, 3:12:24 PM7/26/16
to Mura CMS
To get categories of a specific content item, or even children of the content item, this Gist I created awhile back might help too: https://gist.github.com/stevewithington/4170872

Cheers!


On Sunday, July 24, 2016 at 9:04:58 AM UTC-5, Franc Amour wrote:

Franc Amour

unread,
Jul 26, 2016, 8:08:20 PM7/26/16
to Mura CMS
Thanks Steve.  I really need to stick a note on my monitor - or my forehead - reminding me to CHECK THE DAMN GISTs !!

Jonas Eriksson

unread,
Mar 20, 2018, 4:48:20 AM3/20/18
to Mura CMS
Hi Steve,
rolling up an old thread here, but as your reply here is 90% towards my goal, I'd thought I add it to this thread as others might find it useful:

I am looking for a small addition to your Gist, not sure how to apply filtering to the output/selection of categories, perhaps you can give me some advice?

Use case:
I have a content item (can be a company), and I have categories in two "main" categories (= top-level categories) contain "Awards" and "Brands" which in turn can contain an unknown number of sub-categories (see screenshot:


When I display all companies in a list or a single company in a detail page view,  I'd like to not just show ALL categories it is assigned to (as your gist 4170872 provides the solution for), but separate the Awards from the Brands, see simplified screenshot here, where the "blue" parts show what I'd like to accomplish:





So if your code from the gist
<cfscript>
// Category Iterator of the CURRENT Content Node
itCats = $.content().getCategoriesIterator();
</cfscript>


could be extended like this:

<cfscript>
// Category Iterator of the CURRENT Content Node in SubCategory BRANDS with ID 9BB39004-3D78-42E4-B43B585A94BB9B49
itCatsBrands = $.content().getCategoriesIterator().where().prop('parentid').containsValue('9BB39004-3D78-42E4-B43B585A94BB9B49');
</cfscript>


it would do what I want - but that doesn't work :-)

(ideally, not using the category ID but its name, but I'm good if it works with just the ID too)

Many thanks for any hints!
Jonas

Steve Withington

unread,
Mar 20, 2018, 9:17:31 AM3/20/18
to Mura CMS
@Jonas,

Here's another gist that may cover what you're trying to do:

Also read the comments section, as I point out in how you could use the gist to do essentially what it is that you're trying to do ;)

Lastly, keep in mind that you can't "filter" an iterator per se. Iterators merely wrap an underlying query, which is accessible via "iterator.getQuery()". Anyway, take a look at my other gist and hopefully that will address your issues.

Cheers,
Steve

Jonas Eriksson

unread,
Mar 20, 2018, 12:51:20 PM3/20/18
to Mura CMS
Thanks Steve, I had looked at that Gist as well, and with the disclaimer that I might be misunderstanding the function (especially after reading your comment) - but is the intention of your Gist 6214658 not to simply list the (kid) categories of a (parent) category? 

i.e. (after copying your function into the contentRenderer.cfc and doing a reload), using this in my code:
<h2>    #$.dspNestedCategories(parentID='9BB39004-3D78-42E4-B43B585A94BB9B49')#</h2>
should show me any categories below the category with the parentID  9BB39004-3D78-42E4-B43B585A94BB9B49, no?

If that is what it should be doing, this would still not show me only the categories of that parent category ID that are actually assigned to my content object (a page for example), correct?

Thanks
Jonas

Jonas Eriksson

unread,
Mar 20, 2018, 1:23:25 PM3/20/18
to Mura CMS
Just reading through the 7-1 docs and I guess the following could work:
  1. Load the category bean (parent category) and get the children categories (ID and name)
  2. use the content bean's categoryid*
  3. check whether the id's are matching, if yes, display children's category name
I'll try that later. :-)

*from the docs:  
categoryidA comma-delimited list of CategoryIDs associated with the content item.
http://docs.getmura.com/v7-1/mura-developers/mura-beans-objects/common-bean-objects/content-bean/
http://docs.getmura.com/v7-1/mura-developers/mura-beans-objects/common-bean-objects/category-bean/
Reply all
Reply to author
Forward
0 new messages