Jump to content

Best way to organize categories.. in this case


maba
 Share

Recommended Posts

Hi All,

I'm ready to start 6/7 projects powered by WordWir.. ehmm.. ProcessPres.. ehmm.. ProcessWire! :)

In the first projects client wants this kind of menu:

WATER

JOINTING
product1
product14
product16
product17
product123
REPAIRING
product1
product14
HOT-TAPPING
product1
product14
product17
product123

GAS

JOINTING
product16
product17
product18
product103
product104
REPAIRING
product1
product14
HOT-TAPPING
product17
product123

OTHER1

JOINTING
product1
product14
product16
product17
product123
REPAIRING
NOPRODUCTS
HOT-TAPPING
product1
product101
product102

OTHER_N

...
...

I want start to create my Product(s) pages, template, etc.. but.. how manage categories?

A product can be used in WATER and GAS application, for JOINTING, REPAIRING and HOT-TAPPING uses but not in OTHER(s) application.

Another product can be used WATER and OTHER1, only for JOINTING and HOT-TAPPING use.

Suggestions?

Product like "post", application like "category" and use like tag?

Thanks,

Marco

Link to comment
Share on other sites

Marco, it's usually very simple: item has one category, but many tags. In your case, I'd go either with repeater with two values (application, use), or rather create pages like this: application_use (you seem to have only three uses):

 water_jointing
 water_repairing
 water_hottaping
 gas_jointing
 gas_repairing
 gas_hottaping

:)

Link to comment
Share on other sites

Philosophically speaking I like to think of Categories and Tags as two directions on a matrix; Categories are hierarchical and are therefore vertical, where as tags are non-hierarchical and therefore horizontal.

Of course this goes a bit squiffy if any one item can have more than one category! Then it belongs to two or more vertical relationships in the family tree, though it could be horizontally related by only one tag.

(I think I need a sit down.)

I suppose that in PW you could actually look at it three ways. Your page layout is a strict tree where any one family member can only be in one part of the tree at a time.

You can create limited categories (using a select system) which have very strict usages. These would be close to the page family tree, but not limited to it (especially further down the tree) and any item can belong to more than one category.

And then you can create tags which are free and can go across all pages - these can be selected and/or created on a page by page basis.

Your menu can either be restricted by how the menu is output from the Pages part of PW, or you can add custom bits of menu straight into the template.

So, you can list things that are linked together by set categories or even by groups of categories (my programming abilities fall over on this, but many here can help).

That way, in theory, not only can you display all services to do with Water, but you could also all jointing services to do with all main headings.

Basically, what I think I am saying is that you don't have to be limited by how the built in page<->menu system works together.

Joss

Link to comment
Share on other sites

Hi, thanks for your answer.

Now I try you suggestions but.. in my case item can have many category an many tags.. in this case: many applications and many uses.

I'm not sure about URL:

/categories/category/item

or

/tags/tag/item

or

/categories/tag/item (??)

What clients would have:

/product/item1

and

/applications/water/jointing/item1

and

/applications/water/repairing/item1

and

/applications/gas/jointing/item1

(redirect to the same item)

But.. make sense?

Or.. redirect all links to /product/item1?

In BlogProfile we have a clear definitions of URL: /categories/ and /tags/ but in this case I've so many doubts.

Probably this is a silly question.

Link to comment
Share on other sites

Talked with the client.

Simple solution: dynamic menu for Application->Use->Products and all the product links are /product/item.

So:

Application1

\_Use1

\__Item1

\_Use2

\__Item1

\__Item2

\_Use3

\__Item5

Where Application1 link is /applications/application1 and lists all uses belonged to application1.

Where Use1 link is /applications/application1/use1 lists all products tagged use1. Is this possible?

Where Item1 link is /product/item1 lists item1 detail.

Where /products/ lists all products grouped by uses and applications.

Link to comment
Share on other sites

I'm replying to the original message, as I'm not sure I totally follow everything after and trying to get through my message queue before 11. :)

The structure you've got there I don't think is ideal because of the repetition. It looks like your products need to be able to appear in multiple categories and uses and various combinations, so I think you are better off taking the structure out of it until you've got some one-to-one relationship that would lend itself to the structure. Further, it looks to me like you need a secondary relation (use) related to the first relation (category), rather than independent from one another. Assuming I understand it all correctly, here's what I'd probably do initially:

products

product1

product2

product3

categories

water-jointing

water-repairing

water-tapping

gas-jointing

gas-repairing

gas-tapping

water-jointing

water-repairing

water-tapping

other1-jointing

other1-repairing

other1-tapping

etc.

Each product would have a multi-select page reference to categories. This works great if you don't have a huge amount of categories. But if you do have a lot of categories, then it the redundancy of having 3 pages (jointing, repairing, tapping) for each category may get annoying. In that case, I would take this route:

products

product1

product2

product3

categories

water

gas

other1

etc.

uses

jointing

repairing

tapping

Then you would add a repeater field called categories_uses (or whatever you want) to your product template that contains two fields: category and use. The category field would be a page reference to your /categories/, and use would be a page reference to /uses/. Both would be single select fields (not multi). Using this strategy, you could edit any product and add as many categories_uses items as you wanted. For each one you'd first select a category and then a use. You could cycle through them in your product template like this:

foreach($page->categories_uses as $item) {
 echo "<li>{$item->category->title}: {$item->use->title}</li>";
}
Link to comment
Share on other sites

Hi Ryan,

thanks for you feedback.

I've tried repeater as you suggest. It works.

But.. After I've talked again with the client I think that there is a simpler solution: two checkbox fields, multi choice.

Uses are linked to product and not to applications. If a product is for jointing and repairing in water applications is the same for gas applications.. (if the product is linked to gas application).

But the menu have to be as described in the first post: for each application list all linked products grouped by use.

Is it possible with the two checkbox fields?

Marco

Link to comment
Share on other sites

If a product is for jointing and repairing in water applications is the same for gas applications.. (if the product is linked to gas application).

Okay that simplifies a bit then. The second structure in my previous message would still be the best one to use, but you can use two multi-selects (categories and uses) without any repeaters. Checkboxes would definitely be nice for the uses, and either checkboxes or asmSelect should be nice for categories. Since all selected uses apply to all selected categories, your output method would be something like this:

foreach($page->categories as $category) {
 foreach($page->uses as $use) {
   echo "<li>$category->title $use->title</li>";
 }
}
Link to comment
Share on other sites

Hi,

done. :)

Menu also. Better way to do this?

echo "<ul>";
foreach($pages->get("/applicazioni/")->children as $application) {
echo "<li><a href='{$application->url}'>{$application->title}</a><ul>";
foreach($pages->get("/usi/")->children as $use) {
 echo "<li><a href='{$use->url}'>{$use->title}</a></li><ul>";
 $products = $pages->find("template=product, applications=$application, uses=$use");
 foreach($products as $product) {
	 echo "<li><a href='{$product->url}'>{$product->title}</a></li>";
 }
 echo "</ul></li>";
}
echo "</ul></li>";
}
echo "</ul>";

(it is the default language)

Marco

Link to comment
Share on other sites

I output a sitemap view of products and their application/uses I think that looks good. You may want to move your $pages->get("/usi/")->children call outside of the foreach loops so that you've got that cached for reuse:

$uses = $pages->get("/use/")->children; 

Technically ProcessWire is caching it for you either way, so it's not absolutely necessary. But it's a good practice since some actions (like saving a page) can clear the memory cache. Though wouldn't matter in this code segment.

Another alternate way would be to pre-cache all the products so that all the filtering is done in memory rather than by the database (potentially faster). Though the method you are already using is more scalable, should things grow to the point where you need to paginate.

$products = $pages->find("template=product, sort=title"); 
$uses = $pages->get("/usi/")->children; 
$applications = $pages->get("/applicazioni/")->children;

echo "<ul>";
foreach($applications as $a) {
 echo "<li><a href='$a->url'>$a->title</a><ul>"; 
 foreach($uses as $u) {
   echo "<li><a href='$u->url'>$u->title</a><ul>";
   foreach($products->find("applications=$a, uses=$u")) as $p) {
     echo "<li><a href='$p->url'>$p->title</a></li>";
   }
   echo "</ul></li>";
 }
 echo "</ul></li>";
}
echo "</ul>";
Link to comment
Share on other sites

Hi,

after some changes.. (use become application and application become sector).

// $products = $pages->find("template=product, sort=title");
$sectors = $pages->get("/settori/")->children;
$applications = $pages->get("/applicazioni/")->children;
echo "<ul>";
foreach($applications as $a) {
echo "<li><a href='$a->url'>$a->title</a><ul>";
foreach($sectors as $s) {
 echo "<li><a href='$s->url'>$s->title</a><ul>";
 foreach($pages->find("template=product, sectors=$s, applications=$a") as $p) {
	 echo "<li><a href='$p->url'>$p->title</a></li>";
 }
 echo "</ul></li>";
}
echo "</ul></li>";
}
echo "</ul>";

without

foreach($pages->find("template=product, sectors=$s, applications=$a") as $p) {

I cannot retrieve products.

First line is commented for this post only.

Why?

Link to comment
Share on other sites

Just to confirm, this is the line that doesn't work?

foreach($products->find("applications=$a, uses=$u")) as $p) {

I can't say for certain why not because I don't have the code in front of me to execute, but make sure you were using $products and not $pages. If you want to test an alternate, it could also be written as this:

foreach($products as $p) {
 if(!$p->applications->has($a)) continue;
 if(!$p->sectors->has($s)) continue;
 echo "<li><a href='$p->url'>$p->title</a></li>"; 
}
Link to comment
Share on other sites

Hi Ryan,

yes, I confirm the the problem.

 foreach($products->find("sectors=$s, applications=$a") as $p) {
	 echo "TEST ONLY: <li><a href='$p->url'>$p->title</a></li>";
 }

prints nothing.

This

 foreach($products as $p) {
	 if(!$p->applications->has($a)) continue;
	 if(!$p->sectors->has($s)) continue;
	 echo "<li><a href='$p->url'>$p->title</a></li>";
 }

works.

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...