Jump to content

Nested Categories


Joss
 Share

Recommended Posts

Morning Folk!

Just sitting here pondering the world as I am just starting to rebuild my sadly neglected portfolio site (http://www.sanglier.co.uk). Currently in Joomla with the Seblod CCK extension, it has always been buggy and I lost interest in putting much content in it - stupid really.

Any way to cut a boring story down to size, I was thinking about categories.

I know how to create the idea of categories with pages and using the pages field to associate them together in various way, but I haven't the foggiest how I can do nested categories or relate the categories to URLs.

So, for instance, if I have a category called "tech" I would want any article in that category to have the url sanglier.co.uk/tech/myarticle

But if it were in a sub category called pw then I would want the URL to be sanglier.co.uk/tech/pw/myarticle

I know this can happen with just using children, but the advantage of using categories is that I can have a separation between the menu layout and the article layout and the possibility of an article belonging to more than one category (if I can work out how that would work!)

Any hints and tips from the great and the good?

Joss

(PS: Sorry for the "granny sucking eggs" explanation of the problem, but I am always aware now that it might not just be experienced users who read these questions and so I feel I have a responsibility to be very clear ... now I am really sounding like the old bear - damn!)

  • Like 1
Link to comment
Share on other sites

Hey Joss,
If I understand you correctly, this is something I do extensively in the sites I'm building now. In addition to placing items in the page tree in the admin area, I create a series of checkboxes, each representing a "category." The user can check off any number of them, thereby creating what I call "instant categories." You can then search anywhere you want based on those checkboxes. For example, you could create lists filtered by any combination of checked boxes. This could apply to menus or any other pages.

You essentially search based on if a box is checked (state = 1).

For example, in your case you could have checkboxes for "tech" and "pw." When you create a page, check one or both of these.

In your template, let's say you wanted to just post the "intro_text" only for the "tech" adticles (whose "tech" checkbox have been checked). You would do this:

<?php
$sangchecks = $pages->find("template=article, tech=1, sort=-date, limit=50");
foreach($sangchecks as $sangcheck)
{
?>
<div id="listings_box">
<img src="<?php echo $sangcheck->intro_text ?>" />
</div>
<?php
}
?>

You can just switch the line calling the tech choice to include both checkboxes if you want:

$sangchecks = $pages->find("template=article, tech=1, pw=1, sort=-date, limit=50");


That takes care of the categories.

To get those checkboxes into your URLs, I will refer you to a post Ryan made on a similar subject a couple of weeks ago:

http://www.processwire.com/talk/topic/1799-routes-and-rewriting-urls/page-2'>http://processwire.com/talk/topic/1799-routes-and-rewriting-urls/page-2

Putting all of this together should get you what you want.

Thanks,

Matthew

  • Like 1
Link to comment
Share on other sites

Hey Joss,

Glad that helped.  I think this is a good topic.  I'd be curious to know about other methods.

The good thing about this is that once your pages are "tagged" with the checkboxes, you can do all sorts of searches and listings based on their status, and at any time you can instantly update them to exist elsewhere, appear in "related" pages, or do any number of other actions on them.

Thanks,

Matthew

PS:

I posted my original material on an iPad, and as you saw the results were very messy!  I ran to my desktop and cleaned it up.  Can someone please check and see if something is going on with the forum software?

Link to comment
Share on other sites

Thanks Matthew - much nice to read now!  :lol:

I tend to use drop-downs using the page field, but it is essentially the same thing.

I add the page field to both my article listing page template and my article template so that I can create a listing page that uses the same categories as the articles do, if you see what I mean.

I am still unsure what to do about nested categories, however.

This is really about SEO. If I have an article under pet food that is a sub category of animals, then it is healthy to have the url as ./animals/pet-food/article

There is possible a trick about listing parents here somewhere since the animals category (which is actually a page of course) is the parent of pet-food.

I need to get my site started and artificially add this so I can see what is happening.

Also, reading your post, I might not go the multiple category route, but rather go for single categories and additional tags. That might be a much better way of cross linking articles. I know that when I have used multiple categories in WordPress it can end up messy. 

Joss

Link to comment
Share on other sites

Creating categories using checkboxes isn't recommended.

Create a nested page structure that represent you categories. Then use a page field to select from them (multiple if needed)

Now the category tree can be used to output a nested navigation for example. In the category template you would enable urlSegments and you can use that simply to list pages that are linked to this category through page field.

The template code for the category pages would look like this:

if($input->urlSegment1){
	// if url segment is a product we get the product to render details page
	if($pages->get("name=$input->urlSegment1")->template == "product"){
		$prod = $pages->get("name=$input->urlSegment1");
	} else {
		// else we get the normal page
	}
} else {
	// in case we are on a "normal" category page, do different stuff
	$cat = $page;
}

Then proceed outputing stuff as usual.

And the navigation using my MarkupSimpleNavigation module would be extremly simple.

$root = $page->rootParent(); // the root page of the categories
$navcol = $nav->render( array('collapsed' => true), null, $root);

This will give you urls like

/categories/cat1/cat1c/

where you can list all product that belong to cat1c.

And have product links like:


/categories/cat1/cat1c/product1

Which can then constructed like this:

<a href='$page->url$prod->name/'>$prod->title</a>

Hope that helps and is understandable.

Not finished but working on a shop that uses this approach here: http://sultan.urlich.ch/shop/

Same is done with ingredients for products. A page of a incredient then lists all products that have the ingredient like here: http://sultan.urlich.ch/zutaten/gewuerze/

  • Like 2
Link to comment
Share on other sites

Hello,

Yes, that's why I kind of describe my method as "instant categories" rather than what you might call "true categories."

The method I describe is a good way to give users power to create actions based on a variety of easy choices, then to use those choices for a number of responses. For example, this could be used to create slideshows or latest news listings based on which pages the user checked as "featured."

It's good to make a distinction between this and "true categories"!

Thanks,

Matthew

Link to comment
Share on other sites

Ta Soma!
 

I had forgotten about your simple nav module. I will play with that also. I need to Twiiter Bootstrapperize (!) it, but that should't be a problem.

I have just had a music rewrite come in, so I need to go and do that first, unfortunately. 

Joss

Link to comment
Share on other sites

If you need one-time toggles, individual checkboxes are a fine way to go. But for multiple related items like categories, the Page reference field is the way to go. You can create a structure of pages representing any amount of flat or nested categories. If you use nested categories, choose the "Page List Select Multiple" as your input type, and set the root level of your categories structure as the "Parent". 

  • Like 3
Link to comment
Share on other sites

 If you use nested categories, choose the "Page List Select Multiple" as your input type, and set the root level of your categories structure as the "Parent". 

Ah, you have just answered a question I was asking myself. Though I think initially, I will possibily want to avoid allowing multiple selections. I was thinking that by using you clever select system, whether you could in affect have a primary category (that would be the first on the list) and secondary categories. Having said that, I think you can get too clever with this sort of referencing.

Once I get my head round this it should turn into another wiki entry, me thinks. Though, once again, it will need to be "this is one way of doing this," because I bet there are other ideas out there!

I will run off and break my server - I mean, go an be constructive

Joss

  • Like 1
Link to comment
Share on other sites

Greetings again.

As always, an intersting discussion here on the ProcessWire forums!

Just taking the definition of the word "category," it means a general or comprehensive division of something.

I've been thinking lately how one of the amazing things about ProcessWire is that it provides a more fluid sense of categories than we usually associate with a CMS, and that with ProcessWire we can give users a more flexible way to move pages among those categories

Sometimes, is category is a "hard" classification, and other times it is a "soft" one. For example, a store site may want snowblowers inside the "big machinery" category (hard classification), but also move them quickly in and out of the "featured" category depending on the weather (and have them appear then disapear from a slideshow accordingly). Both classifications are "categories," in their own way. One moves a lot, the other doesn't.

Sorry Joss, I seem to be veering into general territory. I know you usually don't mind that though!

Thanks,

Matthew

Link to comment
Share on other sites

I've been thinking lately how one of the amazing things about ProcessWire is that it provides a more fluid sense of categories than we usually associate with a CMS, and that with ProcessWire we can give users a more flexible way to move pages among those categories

Actually, really it doesn't give any sense of categories at all - so, like with many other things, you are starting with a blank slate.

Strangely I am finding that a bit of a problem. I am staring at a blank notepad and trying to work out how I am going to break up my portfolio site. Normally, I would have little choice but follow the normal method of which ever programme I am using - it may not be the best way, but following blindly is an easy thing to do.

Now I have rather a lot of options and I am seeing that my waste basket is beginning to fill with discarded scenarios while my notepad is offering little comfort or suggestion.

???

Link to comment
Share on other sites

Joss, that's true actually, however in my book this is a big plus, because you start thinking again about things you would never have before! Think about structure carefully and where it really matters at the end. You just need some time to find your way through it and what drawbacks there could be. After some projects this becomes second nature really. It's been always like this, in that you first need to eat of everything to decide which is better.

Link to comment
Share on other sites

Greetings Joss,

That's exactly what I mean!  With ProcessWire, the idea of a "category" is suddenly wide open and has lots of subtlety.  With other systems, like Joomla and WordPress, a "category" is a very pre-defined nugget.  In addition, what can be done with a category is also very pre-defined.

Again, this brings me back to the idea of "hard" and "soft" category types.

Going further, there is even greater potential for creative sub-division within the category types.  For example, in Joomla you can run a "blog" listing of everything in a category, but you cannot pull out one field from each item in the category to create a unique listing, and never mind creating two, three, or four different listings of the material based on what was entered within particular fields.  In ProcessWire, regardless of which "hard" or "soft" category a page belongs to, you can grab certain fields and create what I guess you could call "virtual" or "instant" categories.

One of the reasons I am latching onto this discussion is because I believe flexibility with "categories" may be one of the most attractive ProcessWire elements to people accustomed to other systems.  I know from numerous Joomla discussions that being able to do more with categories is a major area of need. To illustrate my point, there are 844 extensions on the Joomla Extension Directory that specifically extend categories.

Thanks,

Matthew

  • Like 1
Link to comment
Share on other sites

After some projects this becomes second nature really. It's been always like this, in that you first need to eat of everything to decide which is better.

Heh!

It is like going back in time to the very first website I made which was with the then, brand new Corel Webmaster Suite! (actually, second - the first was on WBS - Web Broadcasting Service)

Coming from the world of film and radio where content is, by its very nature, linear, I had to start thinking about a hierachy.

Though, having said that, one thing I forgot back then is that even working linear, you have to prioritise, not vertically, but temporally; each section or chapter must have its headline, its important facts and then its justification. A vertical Hierarchy should have the same thing somewhere along the line.

It almost needs three sorting systems:

  1. Categorisation - your standard filing cabinet where a major headline reference is strictly limited to one folder (the old paper variety)
  2. Tagging - not a random "I think I want this keyword" system, but a strict, horizontal associative system that creates links between different parts of the hierarchical tree
  3. Order of importance, or perhaps Reading Order - where information that is associated either within a category or within a tag linked list is prioritised on the basis of what sort of information it is.

That last one is really "out there" and is how a few of my relations like to work - they are heady, scientists (mostly ageing profs, these days) and like to sort information in several ways for research purposes. They all hate WikiPedia, in consequence, because they say there is no subjective or objective prioritisation and without that, you cannot truly judge the importance or context of any particular piece of information. Bloody fussy lot, basically! :)

  • Like 1
Link to comment
Share on other sites

  1. Categorisation - your standard filing cabinet where a major headline reference is strictly limited to one folder (the old paper variety)
  2. Tagging - not a random "I think I want this keyword" system, but a strict, horizontal associative system that creates links between different parts of the hierarchical tree
  3. Order of importance, or perhaps Reading Order - where information that is associated either within a category or within a tag linked list is prioritised on the basis of what sort of information it is.

No.3 (although ordinals aren't showing in the forum at time of writing) could also be 

  • Date (blogs often use most recent)
  • Popularity (from site stats, maybe, or social likes or whatever)
  • Arbitrary (alphabetical or something, although Jakob Nielsen disagrees and offers suggestions relevant to this discussion)
  • Or how about something like a score that the author gives to a piece (like a z-index?!?) to force it to show up early in searches and other listings (I'm probably thinking like 'featured products' on an e-commerce site)

<edit>Ordered lists might need some css attention but unordered lists are ok</edit>

Link to comment
Share on other sites

Categories vs tags, anyone?

To my mind they can be the same thing in PW.

What I have on one site is what a lot of others here do - have a hidden Tools page and under it I created a page called Tags and then put the tags under that. Then, using a Page field I can tag my articles.

Articles are stored under /articles/article-name/ . When viewing an article, you see the things it's tagged against.

The next bit is where cateegories and tags become interchangeable, because if it's a small list of tags I would then have a category list down the left based off those tags, so when you click it it returns all articles tagged in that category.

This way of doing it provides endless options - people can browse by "category", or land on a specific article on your site and click a tag in the list against that article to view others in that "category".

The lines are now totally blurred, but you get the best of both worlds. Of course the other option if you think you want a limited number of categories but maybe hundreds of tags over time is keep them totally separate, which is also fine.

Not sure whether that was much help, but I think if you have a think about how many categories and tags you might have for your current content and whether there is a lot or just a little crossover between them then this will help you make a decision on what to do in terms of structure.

Link to comment
Share on other sites

Evening Dave of Chorley!

Yes, the third item could be various criteria,

If you were looking at it from a document point of view, it could be said to be in this order of priority

  1. Title
  2. Oveview
  3. Executive Summary
  4. Premise/Objectives
  5. Research Criteria
  6. Research Method
  7. Results
  8. Conclusion

All of those sections could also have linked sections, often taken from other documentation, that expand on methods or practice or analysis and so on.

You could just have all these as one document, but it is more interesting to have them as separate items that are combined in this strict order for presentation purposes.

So, each could belong to a category that defines what type of text they are (research or results and so on), then separately tagged to see how they link to similar items that are categorised in the same way (say, chemical research, botanical research, etc), and then finally prioritised into document form. Of course, that final form may be subject to separate categorisation ...

It could make you quite ill!

EDIT:

PETE!!! Ordered lists are not displaying.....

EDIT 2

Okay, they are now

Link to comment
Share on other sites

Actually, really it doesn't give any sense of categories at all - so, like with many other things, you are starting with a blank slate.

You could also look at it from the point of view that almost everything is (or at least can be) a category. Not a blank slate at all. In my opinion, traditional categories are very limited. And I always struggle with that when using other systems. 

Link to comment
Share on other sites

You could also look at it from the point of view that almost everything is (or at least can be) a category. Not a blank slate at all....

Okay, this is getting into hippy territory (and I am one of the few here qualified to make that judgement)

So, if EVERYTHING is a category, like in the whole universe and other places too, would that include each individual user in the sense that they are originating the content and are therefore the logical hierarchical parent?

If so, I am going to have to rethink the starting point of my tutorial....  :)

Link to comment
Share on other sites

Hey Joss,

I totally get what Ryan is saying.  You end up there naturally (I believe) once you break away from the idea that most CMSs force on you regarding categories.

I think most of the rigid ideas of categories come from the fact that other CMSs have no choice but to deal with them that way.  Think of how Joomla (for example) handles categories.  It just does not have the ability to allow articles to be parsed into numerous different directions at once.  Why?  Because it is based on the idea that there has to be a top-level set of assumptions that everyone who uses the system adheres to.

With ProcessWire, we are completely open to placing pages any way we see fit -- either as rigid categories or soft categories (i.e., virtual, instant, etc).  Once that opens up, you then are able to just look at your information and realize that categories should be smooth and almost borderless.  Just embrace it!

This difference in flexibility is not limited to categories.  However, from my experience with other CMSs, I think categories are an excellent way to show the core difference between ProcessWire and other systems.

Yes, OK, it's kind of hippy in a way.  If so, well, then ProcessWire is part of the revolution man!  Just look at it with kaleidoscope eyes in a strawberry field forever and you'll be all right.

Peace,

Matthew

Link to comment
Share on other sites

No I think WillyC has some insight here. A page tree can be a type of fractal, which is what I think he's trying to show with that image. And the man is presumably creating and manipulating the tree (fractal) as you would in ProcessWire. 

the.nature 

the real secret of category 

is the.world made of category. 

  the  world made.of page

catpage

Translation: the nature/secret of categories is that they are just pages. world=your site, catpage=category+page. So your site is made of categories or pages, and the distinction does not matter as it's all the same. 

in.catpage

if you.know catpage.that world is made of you.make of it 

Translation: Once you know the true nature of pages, you can create anything. Self actualization or something?

Do I have this right WillyC?

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...