Jump to content

Regarding page reference for page/product's categorization


adrianmak
 Share

Recommended Posts

I knew that page reference field can be user for categorization.

Is it possible to select a child root as page reference.

Take an example.

I created a page named Categories, the page structure look like below

Home (site root)

  +--About Company

  +--Our Services

  +--Product

  +--Contact Us

  +--Categories

       +--News

            +--Company news

            +--Market news

       +--Products type

            +--plastic

            +--metal

       +--Pictures type

            +--plastic

            +--metal

            +--paper

            +--company

The child pages , News, Products type, Pictures type, under categories are no association to each others.

For a Product page with a page reference field, only "Products type" has meaning to Product. Could I select "Products type" child root  as page reference ?

Link to comment
Share on other sites

Yes, if you have a page reference field that is specific to Product pages, you can go to the field settings, under the Input tab and then select Products type as Parent of selectable pages. Or use one of the other settings.

If your page reference field is used on different kinds of pages (Product, News etc.) and you want a 'dynamic' Parent of selectable pages, depending on the type of page it is used on, maybe this can be done via the custom php option. Some sort of conditional parent, but i'm not sure if possible.

Link to comment
Share on other sites

  • 3 weeks later...

one more question regarding page reference.

From op, I grouped categories into three groups  , News, Products type and Pictures type

In which each group is referenced by three template independently

ie

News is referenced by News template

Product type is referenced by Product template

Pictures type is referenced by Picture template

How could I create a single page field type and dynamic associated each group for each page template.

Instead of create three  different category input fields

Link to comment
Share on other sites

News is referenced by News template

Product type is referenced by Product template

Pictures type is referenced by Picture template

How could I create a single page field type and dynamic associated each group for each page template.

Instead of create three  different category input fields

In your page field settings go to Input, expand “Custom PHP code to find selectable pages” under “Selectable Pages”. You can fill your input field according to the template of the page being edited, by checking $page->template:

if ($page->template->name === 'News') {
    return $pages->find('parent=/categories/news/');
}
else if ($page->template->name === 'Product') {
    return $pages->find('parent=/categories/products-type/');
}
else if ($page->template->name === 'Picture') {
    return $pages->find('parent=/categories/pictures-type/');
}

Make sure to remove all the other options from “Selectable Pages”. Sometimes they don’t get overridden properly.

  • Like 1
Link to comment
Share on other sites

In your page field settings go to Input, expand “Custom PHP code to find selectable pages” under “Selectable Pages”. You can fill your input field according to the template of the page being edited, by checking $page->template:

if ($page->template->name === 'News') {
    return $pages->find('parent=/categories/news/');
}
else if ($page->template->name === 'Product') {
    return $pages->find('parent=/categories/products-type/');
}
else if ($page->template->name === 'Picture') {
    return $pages->find('parent=/categories/pictures-type/');
}

Make sure to remove all the other options from “Selectable Pages”. Sometimes they don’t get overridden properly.

Thank you very much.

Link to comment
Share on other sites

Last night, I implemented the custom php code to find selectable pages.

Pages structure

post-2272-0-20323100-1452559647_thumb.pn

Here is my code

post-2272-0-28014700-1452559605_thumb.pn

The categories of pages under "News" pages could get the right categories from "Categories" correctly.

post-2272-0-30559300-1452559741_thumb.pn

However, PW returned an error with a selected category of this page.

"Error saving field "categories" - Page 1046 is not valid for categories (Page 1046 does not have required parent 1)

post-2272-0-50066100-1452559842_thumb.pn

PS it's working for the "Recycling Library"

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