Categorisation Package for Umbraco - How to list categories and assigned documents
Is there a tutorial out there that might help me display the
categories that I’ve created and assigned to my docs? Razor would be
preferable if possible. Basically, I’m trying to have something like:
Boats (Link to list page of Boat Articles)
- Recent Document 1 about Boats (Link to Doc)
- Recent Document 2 about Boats (Link to Doc)
- Recent Document 3 about Boats (Link to Doc)
Cars (Link to list page of Cars Articles)
- Recent Document 1 about Cars (Link to Doc)
- Recent Document 2 about Cars (Link to Doc)
- Recent Document 3 about Cars (Link to Doc)
I’ve having the toughest time organizing by categories.
Below is a bit of code that should help. It assumes the following things;
Category pages are children of the current page.
Category pages have a property with alias 'category' which contains the ID of the category the page is associated with (in your example it would list pages in that category).
Categories which are assigned to nodes are in the property with alias 'categories'.
The above code will list category pages and the latest three pages which have that category assigned.
At the moment there is no single category selection data type, so the ID would have to be entered manually on the category page, but I've noted this for future releases of the categorisation package.
I uploaded a new version of the Categorisation package today - version 2.2.0.0. There is now a single category data type named Category Picker and a new static method in the Categories class named FindCategoryByName which should be helpful to you.
There's a couple of ways to do this, it depends on the technique you want to use. It would be straight-forward to create a user control listing all categories using Categories.GetCategories(), which returns an array of all active categories, then output a link for each category using the current page URL and appending each category ID as a query string parameter. Then you can query Umbraco for nodes/pages with the selected category by using NodeHelpers.GetNodesInCategory().
If you want to use XSLT then there are extensions like GetCategories() for getting all active categories and listing them.
I did what you said and created an XSLT that lists all the categories. I appended the id in to the querystring. I then created a user control that filters the results depending on the value from the querystring.
I want to display the categories added to the blog. I used a macro to xsl (from example). I can't display it. Could you please help me... I need to change something in the code?
Sorry for the late reply, I've been in Belgium all week (without a laptop!) and commenting on threads doesn't work on an iPhone for some reason.
I had a look and was suprised to see I'd left it out - this is a mistake and will be corrected. I should have some time on Sunday so hopefully I'll get a small update out then.
i uninstalled the version I had and reinstalled the new update. Now I seem to be getting the following error everytime I go in to the content:
Server Error in '/' Application.
Value cannot be null. Parameter name: name
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: name
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Are you using Umbraco 6.0.3? If so, I know there's a problem with this version as I saw the same thing yesterday. I haven't had a chance to find out what the problem is though. From my quick scout around on the forum yesterday it didn't seem like it was specific to my package.
Hopefully I'll have a chance to look at this soon.
It is very strange. As a test I create a new umbraco site without the categorisation package and the content loaded fine. I then added the older version of the categorisation (2.2.1.0) and I get the same error as above when trying to load the content.
If I remove the categories property it loads ok but without the category selection :(
Another strange thing I have noticed is that if I try and create a new data type I have no option to create a new CategoryTree (property editor). Only category picker is available.
I know this is a problem occuring with other packages too, I think something has changed in Umbraco 6.0.3 to cause this.
I do think it's related to that link but, like you say, the solution in that case doesn't work here for some reason - it was something I tried yesterday afternoon.
Thanks for the information, I'll look into this issue as soon as I can.
I spent all day yesterday looking at this and have finally found a work around. The issue is related to the DataType, if you create a new DataType with the Category Tree as the property editor and save it (also re assign the property within the document type). This will fix the issue.
It is a massive pain though and hopefully Umbraco can sort this out in a new release.
Where do you reckon I should log this as an issue? i'm still new to Umbraco so not quite sure the best forum to log this on?
Drag and drop would be an outstanding addition to the Categorisation tree if you do something similar, perhaps levereging this code to work. The developer of this Jeremy Pyne has a Google+ page should you want to ask him about it. https://plus.google.com/u/0/s/umbraco%20pyne?cfem=1
Categorisation Package for Umbraco - How to list categories and assigned documents
Is there a tutorial out there that might help me display the categories that I’ve created and assigned to my docs? Razor would be preferable if possible. Basically, I’m trying to have something like:
Boats (Link to list page of Boat Articles)
- Recent Document 1 about Boats (Link to Doc)
- Recent Document 2 about Boats (Link to Doc)
- Recent Document 3 about Boats (Link to Doc)
Cars (Link to list page of Cars Articles)
- Recent Document 1 about Cars (Link to Doc)
- Recent Document 2 about Cars (Link to Doc)
- Recent Document 3 about Cars (Link to Doc)
I’ve having the toughest time organizing by categories.
Hi Patrick,
Below is a bit of code that should help. It assumes the following things;
The above code will list category pages and the latest three pages which have that category assigned.
At the moment there is no single category selection data type, so the ID would have to be entered manually on the category page, but I've noted this for future releases of the categorisation package.
If you have any questions, let me know.
Cheers,
James
Hi Patrick,
I uploaded a new version of the Categorisation package today - version 2.2.0.0. There is now a single category data type named Category Picker and a new static method in the Categories class named FindCategoryByName which should be helpful to you.
Thanks,
James
Hi
Does anyone know how I can do the following?
1. List all the categories on a page as links
2. When a user clicks on a category it then filters for all the pages that has the category assigned.
Any help much appreciated
Mark
Hi Mark,
Have you had a look at the documentation?: https://umbracocategories.codeplex.com/documentation
There's a couple of ways to do this, it depends on the technique you want to use. It would be straight-forward to create a user control listing all categories using Categories.GetCategories(), which returns an array of all active categories, then output a link for each category using the current page URL and appending each category ID as a query string parameter. Then you can query Umbraco for nodes/pages with the selected category by using NodeHelpers.GetNodesInCategory().
If you want to use XSLT then there are extensions like GetCategories() for getting all active categories and listing them.
If you need some code samples then this is something that can be added to the samples project (http://our.umbraco.org/FileDownload?id=4755)
Thanks,
James
Cheers James, I managed to do this in the end.
I did what you said and created an XSLT that lists all the categories. I appended the id in to the querystring.
I then created a user control that filters the results depending on the value from the querystring.
Seems to work really well.
Thanks
Mark
Excellent. Glad you got it working!
Cheers
Hello,
Could you please help?
I want to display the categories added to the blog. I used a macro to xsl (from example). I can't display it. Could you please help me... I need to change something in the code?
I have categories:
1) main news
- news type A
- news type B
-
Cheers
Peter
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:Auros.Categories="urn:Auros.Categories"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Auros.Categories ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="categoryXml" select="Auros.Categories:GetCategoriesFromCSV($currentPage/categories)" />
<xsl:if test="count($categoryXml//category) > 0">
<ul>
<xsl:for-each select="$categoryXml//category">
<li>
<xsl:value-of select="./name" />
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Hi Peter,
I'll have to test this out later, but I'm not seeing anything wrong right now.
Try a couple of things to troubleshoot this;
If all seems fine;
Thanks,
James
Hi James
Do you know if it is possible to get the id of the categories using GetCategories()?
Thanks
Mark
Hi Mark,
Sorry for the late reply, I've been in Belgium all week (without a laptop!) and commenting on threads doesn't work on an iPhone for some reason.
I had a look and was suprised to see I'd left it out - this is a mistake and will be corrected. I should have some time on Sunday so hopefully I'll get a small update out then.
Cheers,
James
Hi Mark,
The ID should now be returned by all the XSLT extensions which return categories as XML, see the 'id' attribute.
Check out the beta release of the package here: https://umbracocategories.codeplex.com/releases/view/105052
Thanks,
James
Thank you very much James
Hi James
i uninstalled the version I had and reinstalled the new update. Now I seem to be getting the following error everytime I go in to the content:
Server Error in '/' Application.
Value cannot be null.
Parameter name: name
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: name
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
I have tried to uninstall and reinstall an old version but I seem to get the same error. Any idea?
Thanks
Mark
Hi Mark,
Are you using Umbraco 6.0.3? If so, I know there's a problem with this version as I saw the same thing yesterday. I haven't had a chance to find out what the problem is though. From my quick scout around on the forum yesterday it didn't seem like it was specific to my package.
Hopefully I'll have a chance to look at this soon.
Thanks,
James
Hi James
Yes i'm using 6.03.
Thanks for your help
Mark
Hi James
It is very strange. As a test I create a new umbraco site without the categorisation package and the content loaded fine. I then added the older version of the categorisation (2.2.1.0) and I get the same error as above when trying to load the content.
If I remove the categories property it loads ok but without the category selection :(
Cheers
Mark
Another strange thing I have noticed is that if I try and create a new data type I have no option to create a new CategoryTree (property editor). Only category picker is available.
Do you think its liknked to this? http://our.umbraco.org/projects/backoffice-extensions/google-maps-datatype/bug-reports/39674-Value-cannot-be-null?p=0#comment146608
I have tried re saving the default values but it doesn't work :(
Hi Mark,
I know this is a problem occuring with other packages too, I think something has changed in Umbraco 6.0.3 to cause this.
I do think it's related to that link but, like you say, the solution in that case doesn't work here for some reason - it was something I tried yesterday afternoon.
Thanks for the information, I'll look into this issue as soon as I can.
Thanks,
James
No worries James.
I spent all day yesterday looking at this and have finally found a work around. The issue is related to the DataType, if you create a new DataType with the Category Tree as the property editor and save it (also re assign the property within the document type). This will fix the issue.
It is a massive pain though and hopefully Umbraco can sort this out in a new release.
Where do you reckon I should log this as an issue? i'm still new to Umbraco so not quite sure the best forum to log this on?
Thanks,
Mark
Hi James
Found a place I can log bugs: http://our.umbraco.org/forum/ourumb-dev-forum/bugs/40164-Error-Value-cannot-be-null-v603
Cheers
Mark
James,
Please take a look at this. We tested this and it works great with the content and media trees. It's based on JS on the client side.
http://pynej.blogspot.com/2013/05/enable-drag-and-drop-on-content-and.html
Drag and drop would be an outstanding addition to the Categorisation tree if you do something similar, perhaps levereging this code to work. The developer of this Jeremy Pyne has a Google+ page should you want to ask him about it. https://plus.google.com/u/0/s/umbraco%20pyne?cfem=1
Thanks a lot Richard! That's something I'll be looking at for sure.
is working on a reply...