Jump to content

Single page, multiple parent hierarchy?


BrendonKoz
 Share

Recommended Posts

The more I read through the API documentation, the more I learn, but the more I also manage to confuse myself at the same time, so I thought it was about time that I just asked my question.

I built a very, very simple management system for my site awhile back. I received a request that during development of my system I never thought would happen, but seemed completely reasonable once I saw the request - apparently EECMS also doesn't handle what was requested though, so I didn't feel too bad. I'll try to explain below once I ask the question:

Is it possible for PW to handle a single page (item/id) under multiple parents within a site's hierarchy?

Example Fictitious Hierarchy 1:

HOME

- Vacuums

- - Wet Vac Cleaning Solutions

- - - Super Clean 2000™

- Household Cleaning Products

- - Super Clean 2000™

Example Fictitious Hierarchy 2:

HOME

- Payroll

- - Paycheck Schedule by Title

- Human Resources

- - Titles and Salary Levels

- - - Paycheck Schedule by Title

So the idea here is that a single page/item ("Super Clean 2000" and "Paycheck Schedule by Title", respectively) only needs to be created and maintained once, but due to logical association should be found as being related to multiple parents within a site's hierarchy (and appear as though they actually are, in fact, children of each parent individually within the navigational structure). Is it possible for Processwire to handle this sort of thing?

Link to comment
Share on other sites

I wouldn't do it that way though if it's going to be the case that you have pages in multiple locations a lot of the time.

Take for example your first structure - most ecommerce packages would handle this y creating the category structure, then adding products and ticking a box in a category lost to assign that product to multiple categories. When browsing the structure you would have a URL of vacuums/wet-vac-cleaning-solutions and under that it would list your product, but when you click on the product it would appear at a URL of something like products/super-clean-2000

I would suggest handling it this way as well, as I'd you use redirects you're essentially taking the user from one category to a completely different category which would make them a bit confused I think.

As such, I would make the structure of your categories under a page called "categories" and create a template for those pages called "category". Then create a page called "products" and a template called "products" for it to use. The product template would need a field called "categories" that uses the Page fieldtype which is set up to allow selection of all pages under the category page.

You then simply add products and select the categories they appear in :)

When editing the front-end categories template to show the relevant products in that category you can simply use a selector to find all products that are in that category.

Sorry, that's a whistlestop tour of how I'd recommend doing it and doesn't sound simple, but it is pretty easy in reality and not as daunting as I've probably just made it sound ;)

  • Like 4
Link to comment
Share on other sites

Yes, you can do that, i.e. using the Redirects module. The idea would be to have one instance of the page with actual content and multiple "clones" of said page which in fact are redirects to the original page.

Redirects module is no good here, since it does redirects without pages. Redirect template would be better here (there are good examples in forum, but in hurry now).

  • Like 1
Link to comment
Share on other sites

There's different approaches to how it can be archived.

I'm building a shop with products with multiple categories possible. I'll quickly show how it's done.

Create template "category" only with a title field. Then build a tree structure that will be hierachical and serve as the navigation. The template need to have urlsegments enabled. That will enable to display products under a category. So the url will be something like /shop/category1/product1/ and in another category the same product /shop/category2/product1/. This will make it easy to have a highlighted navigation.

The product template will have fields you need and create them under one separate tree. In that template you add a page reference field "categories" that has set the categories tree parent as parent, and a multiple select to browse and select them.

Then this following php code will handle the navigation and rendering of the products. This is in the template for the category template.

$prod = null;

$nav = $modules->get("MarkupSimpleNavigation");

/*
*
* If on shop category pages
* All category pages use "shop" template
* "shop" template has url segments and page numbers enabled
* So urlSegment is always the first (1) when browsing the categories
* Once the page is of type "product" we use that information to output details
*
* This most easy setup with navigation and categries nested unlimited
* and multiple categories per products
*
*/

if($input->urlSegment1){
   // the page is a product?
   if($pages->get("name=$input->urlSegment1")->template == "product"){
       $prod = $pages->get("name=$input->urlSegment1");
       $current = $page;
   } else {
       // else we get current page
       $current = $pages->get("name=$input->urlSegment1");
   }
}
else{
   // in case we are on a "normal" page, do different stuff
   $current = $page;
}

$root = $page->rootParent();

echo "<div style='float:left;width:30%'>";
echo $nav->render(null,$current,$root);
echo "</div>";
echo "<div style='float:left;width:68%;margin-left:2%'>";

// detail page
if($prod){
   echo "<h2>$prod->title</h2>";
   echo "<p>$prod->body</p>";
}
else {
   // list page
   $prods = $pages->find("template=product, categories=$current, sort=title");
   foreach($prods as $p){
       echo "<p><a href='$page->url$p->name'>$p->title</a></p>";
   }
}

echo "</div>";

There's variations how this can be setup, but this gives a very easy and flexible setup, with a navigation that is highlighted and can have multiple categories for one product.

  • Like 2
Link to comment
Share on other sites

Okay, it seems I have some more reading and comprehension to do then. I really don't want a redirect, but after reading yellowled's response it then got me thinking about using a ("clone"?) template that could request a page fieldtype and simply pull all of its information. The only difficulty stemming from that would be requiring users to then manually find the original source to modify the content. ... but somartist might have a slightly nicer implementation (I'll have to look it over more carefully to see what it truly does).

I'm about to leave for a 4 hour drive to visit family for an extended weekend, so I have not had a chance to fully grasp every one else's responses, but I wanted to drop in really quickly and say "THANK YOU!" as it not only shows the power of Processwire, but also the strong community support. You're all awesome. Hopefully Monday evening when I get back I can look this over and get a much clearer sense of it all.

  • Like 2
Link to comment
Share on other sites

We're using an approach similar to soma's in a hotel management system where we're listing Rooms per price range.

Home

- Rooms

-- Standard Room

-- Fancy Room

-- Family Room

-- Junior Suite

- Browse by Price Range

-- Less than $100

--- Standard Room

--- Fancy Room

-- $100 to $200

--- Family Room

We created a hidden page called Price Range, and beneath it pages for corresponding price ranges. And then for the template of the rooms we added a single selection page reference for its price range. Although, like soma, we had to add additional php handling to display the navigation bar correctly for Browse per Price Range, based on the page reference of the rooms.

I'd post some code later if I'm free.

Enjoy your weekend, people!

Link to comment
Share on other sites

  • 5 months later...
You then simply add products and select the categories they appear in :)

I'm quite new to PW and just want to make sure I've got this straight.

Are you saying that in PW, you'd have:

Categories

- Category 1

- Category 2

Products

- Product 1

- Product 2

and that you'd use the Pages fieldtype to relate Product 1 to Category 1, 2, etc.?

Also a question for Soma, with the method you're outlining do you end up with the same page but served at different URLs? Does that not cause problems with duplicate content with the search engines?

Link to comment
Share on other sites

Tyssen, I think that is the cleanest solution, if you want to support multiple categories per product.

Multiple urls for same content: yes, possible seo problem, but as far as I know with using canonical url meta tag you can avoid that: http://googlewebmastercentral.blogspot.fi/2009/02/specify-your-canonical.html Of course one url should be the "real one" where others refer.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

@tyssen - You could assign the canonical URL to your "primary category"  which could be the first selection from the page reference field (assuming multiple selects allowed) as en example or a better choice for users would be to create an additional field for this purpose (another page reference only allowing one selection of a "category" page).  

Apeisa is correct in that using the canonical meta tag does address the duplicate content issue with Google,  and Bing (and thus Yahoo).   Therefore if you have duplicate content at different URL's and you care about your sites ranking,  you should absolutely be using the meta tag. 

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