Jump to content

Input Field Type for multi-level deep 'Categories'


Recommended Posts

Hello everyone,

Brand new to PW and after few hrs loving the potential and control but hating my state of ignorance :)

I understand that page hierarchy is one way to organize (categorize) content so I am trying to build Categories for use in a Blog type of content.

So far, I have made a page called "Categories" with simple just "title" field and created children records (subcategories).

post-435-0-59256200-1329612669_thumb.png

In my 'blog' I created a field called "categories" and used it to pull records from the page above.

However, any input field type I choose does not pull children records and only parents are shown.(i.e camping and photography)

post-435-0-63894100-1329612911_thumb.png

The only field type that is capable is "PageListSelectMultuple*" but unfortunately there is no way to prevent duplicated categories/pages to be selected.

Checkboxes would be my preference but not sure how to go about it all or what am I missing in the setup.

Thank you for your time.

O.T. but where would I find 'skyscraper site profile' to download?

Link to post
Share on other sites

Hi, biotech and welcome!

Actually, despite you can choose a page twice or even more times using PageListSelectMultuple, after you save the page all the duplicated pages will be gone as it allows to have the same page only once.

Link to post
Share on other sites

Thanks for the answer Slkrm, that is pretty sweet feature to know.

I still have some newbie questions:

- So is the approach above the way to go about making categories correct though?

- Is there no way to use checkboxes for categories (with subcats) like in WP?

PageListSelectMultuple is memorizing first time around but the tree expanding can get slow.

Thank you.

Link to post
Share on other sites
- So is the approach above the way to go about making categories correct though?

Biotech, I think you can safely use this approach. Not sure though wether you need both categories and subcategories. If it's a personal blog I think it can be a little bit of overkill. I would just create one level of categories, and if it's not sufficient I would add tags. But it's my very personal point of view :) And if you are dealing with huge multi-user blog with a lot of articles, this structure is the way to go.

However, any input field type I choose does not pull children records and only parents are shown.(i.e camping and photography)

As for checkboxes. I think you might create a dedicated template and use it for your sub-categories aka pages. Then you could use an option in your field settings to set selectable pages by the template they use and not by their parent. Is it what you need?

I'm not sure how it's done in Wordpress, but I think you can have it even better with Processwire, because you can always code your own Inputfield the way you want or customize already existing.

PageListSelectMultuple is memorizing first time around but the tree expanding can get slow.

If you worry that PageListSelectMultuple can't handle big number of pages - just don't! I think Ryan could explanain how it's all optimized to work with hundreds or maybe even thousands of pages ;)

Link to post
Share on other sites

Thanks slkwrm for hanging with me.

I am ok with simplicity of cats too but most of my 'blogging' users will be more familiar with true hierarchy of categories rather than pages. Even the concept of 'go to page called 'blog-categories' to edit categories' is a little different.

I think you might create a dedicated template and use it for your sub-categories aka pages

This could be the case but not sure where to start. What would that page need to output? Some text string or array or straight up html form with checkboxes?

Not much of a php guy, most of experience comes from ExpressionEngine and 'tag' based world.

Is 'skyscraper site profile' used in demo somewhere where it can be downloaded? Would love to see examples how some other concepts are done such as template breakdowns an includes, breadcrumbs, master-detail pages, pagination, logged in/out conditions, search composed of cats and custom fields etc. etc.

So much to learn :)

Thanks again.

Link to post
Share on other sites
I am ok with simplicity of cats too but most of my 'blogging' users will be more familiar with true hierarchy of categories rather than pages. Even the concept of 'go to page called 'blog-categories' to edit categories' is a little different.

Well, maybe you shouldn't tell your users categories are pages :)

The page in PW is very close to a "node" consept in Drupal. Users, roles, permissions are actually pages. And having such a powerful tool like custom fields (aka fieldtypes) at your command you can create any kind of pages which can serve very different purposes going far beyond traditional usage. And thanks to great API you can get all the data from that pages' fields very easily.

I think you might create a dedicated template and use it for your sub-categories aka pages

This could be the case but not sure where to start. What would that page need to output? Some text string or array or straight up html form with checkboxes?

The key point here is to understand what are templates in PW. When I just registered here on forums I didn't quite uderstand what it was. I'll quote Apeisa's answer which he PM'ed me back then, 'cause it's short and comprehensive:

Template means two things in pw:
  • It is actual template file, normal php file which renders the output (usually output is just html page, but can be anything: json, xml... no limits here).
  • It is also "content type", so template has always fields that tell what kind of data page can have.

This is kind of simplification, but it makes very straightforward when building sites: you always know what files create the output (well, you can use same "template file" for different "templates" and you can actually use same fields for different templates [in P21 at least] so it is more flexible than that).

Using $page and $pages API-variables in your template file you can get and then output any data you want and the way you want it. PW doesn't output any markup (but in some cases it provides reasonable defaults, e.g. for pagination), so it's up to you what's on your page and how it looks.

I heard many good things about EE, but I'm not familiar with it. I think there are people here on forum with some EE background, who can draw some analogies or compare PW with EE.

After you've read all the documentation pages on the website, try to use forum search to find many ready-to-use recipes, since all the most typical questions has already been answered (try to request breadcrumbs, template, pagination etc.). Also I recommend you to add Soma's brilliant Processwire cheat sheet to your bookmarks, it will save you a lot of time.

Here is an interesting thread about some advanced tips regarding different aproaches of templates organization.

Also check out this thread, may be helpful as w(h)ell :).

P.S.: As far as I know Ryan can send you skyscraper site profile on request, try to PM him about it.

Hope it helps.

Cheers.

Link to post
Share on other sites

Great answers Slkwrm. Biotech, thanks for your interest in ProcessWire. I only have the skyscrapers profile for PW 2.0 available. I can send it to you, but so much has changed since then that I'm not sure it's the best example anymore. I do plan to update it, hopefully soon. Just need to get a couple free hours to do it.

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By jds43
      Hello, I'm trying to list the categories, on the front through select options, that have been selected by page reference field (multiple pages PageArray) on the child pages.
      Things to Do (would only display three, six, seven, nine in select)
      -thing one (-category three, -category nine)
      -thing two (-category six, -category seven)

      Lodging (would only display one, two, three, four in select)
      -lodging one (-category one, -category two)
      -lodging two (-category three, -category four)

      Dining (would only display five, six, seven, eight in select)
      -dining one (-category five, -category six)
      -dining two (-category seven, -category eight)
      Categories(hidden page)
      -category one
      -category two
      -category there
      -category four
      -category five
      -category six
      -category seven
      -category eight
      -category nine
      -category ten
      $categories = $pages->find(1129)->children('include=hidden'); foreach($categories->references('category') as $ref) { echo $ref->title; } This selector isn't working, but it seems 'references' would be helpful. I've never used it before, so I'm not sure how to employ for this.
      https://processwire.com/blog/posts/processwire-3.0.107-core-updates/#page-gt-references
    • By stanoliver
      Good morning everyone!
      I have a growing number of posts about cars, bikes, airplanes, etc. 
      The following code (below) just works fine and returns only the posts of the category=cars as I desired together with pagination.
      In my url I have for example /categories/cars/car1 or /categories/bikes/bike1
      I do want to filter my posts not only with ... category=cars ... but also with category=bikes or category=airplanes and at best:
      If my url is /categories/bikes/ then ... category=cars ... should be overwritten or replaced by ... category=bikes ... 
      If my url is /categories/airplanes/ ... then the filter should be ... category=airplanes ... (I know a work around by creating almost identical templates where I could just change the "category=cars" part of my code but that's comes of a prize by repeating a lot of identical code and is not a good habit). In the documentation I read something about the "has_parent" selector but I could not get to work it related to the urls mentioned above.
      <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=cars, limit=5, sort=-postdate') as $post 😞?> <!-- Blog entry --> <div class="g8-card-4 g8-margin g8-white"> <!--<img src="/g8images/bridge.jpg" alt="Norway" style="width:100%">--> <div class="g8-container"> <h3><b><?= $post->title; ?></b></h3> <h5>Datum: <span class="g8-opacity"><?= $post->postdate; ?></span></h5> </div>   <div class="g8-container"> <p><?= $post->posteditor; ?></p> <div class="g8-row"> <div class="g8-col m8 s12"> <p> <a href="<?= $post->url; ?>"><button class="g8-button g8-padding-large g8-white g8-border"><b>Details lesen &raquo;</b></button></a> </p> </div> <div class="g8-col m4 g8-hide-small"> <!--<p><span class="g8-padding-large g8-right"><b>Comments &nbsp;</b> <span class="g8-badge">2</span></span></p>--> </div> </div> </div> </div> <!-- END BLOG ENTRIES --> <?php endforeach; ?>   <? echo $results->renderPager(array( 'nextItemLabel' => "rückwärts", 'previousItemLabel' => "vorwärts")); ?>
    • By adrian_gp
      Hello everyone,
      I'm new in this forum and my english is not perfect so sorry for the mistakes.
      I have an Blog Project and i will use categories. 
      Here is the structure:
      Blog -> displays all the Blogposts (template=BlogPage) Post-Name -> display the specific Post (template=BlogPost) Categories -> not visible in the menu (template=CategoriesPage) Categorie-Name -> not visible in the menu (template=CategoriePage) For your information:
      (BlogPost) every blogpost has its own page (BlogPost) in Admin i can select the categorie per Field -> SelectMultiple Pages (Checkbox) (fieldname=categories) (Blog) displays all the BlogPosts and all the categories under the ParentTemplate CategoriesPage, which also have their own side Now the Problem:
      On Blog -> I would like to click on a category and only see the post that has this category checked in the BlogPost.
      CategoriePage -> what do I have to insert there to show only the specific posts which use the checked categorie?

      Let me know if you need more information

      Thanks for your support
       
    • By zaib
      I've a page "blog" which have child pages (blog posts). Right now I've 11 pages (blog posts) and I'm fetching all the posts in my "blog" pages which displaying fine, Issue is only 10 results are showing this is how I'm fetching
      $entries = $pages->find("template=blog-entry"); foreach($entries as $entry){ <a href='{$entry->url}'>$entry->title</a> }  
    • By obesegiraffe
      Hi all, first time poster on the forums but long-time user of Processwire. I couldn't find this exact problem in the forums and I'm hoping it's just something simple I'm missing (first day back from vacation so I am a little brain dead). 
      I have a Select Options Field Type where the client can choose an array of numbers. If nothing is chosen, nothing is outputted onto the page. This works for most pages using this specific template. However, on just one page where I have the field set to blank, I am finding it is still outputting "0", when it actually shouldn't be outputting anything. My code:
      <?php if($page->percent_leased->has('id!=0')){ ?> <h2><?=$page->percent_leased->title?>% Leased</h2> <?php } ?> On this specific page, it is outputting "0% Leased". It's also doing something kind of weird in the database under the percent_leased field type. It's repeating the same ID of the specific problem page twice (page ID 1086) when I set it to blank. It works fine if I actually choose a number and the duplicate goes away. I've never really delved deep into the databases so maybe this is normal? 

      The weird thing is is that this is working fine on all other pages using this template. It's just this one page acting weird. FWIW, this particular site is running version 2.6.1. 
      Thanks for reading!
×
×
  • Create New...