John W. Posted February 16, 2016 Share Posted February 16, 2016 Hi Guys, I've been stuck since yesterday and after reading forum threads, watching pw videos, I still can't seem to get this. I'm setting up a directory where an item can be in multiple categories. I sorta have it working to a point from what I read from an old post, and a reply that Ryan had left regarding the structure and using the Page Fieldtype, here : https://processwire.com/talk/topic/2541-business-directory-website/?p=24591 To keep it simple for testing, and try to explain the problem, I have a page called music with 3 categories, ROCK, POP and FOREIGN. If I click on POP, for example, I can add the band ABBA -- at which point I also have a complete list of all categories that the user can also choose to put ABBA in the FOREIGN category (I'm using the Page Fieldtype to list all categories). However, when I save the new entry the band ABBA only shows up in the category it was originally created (POP), but, doesn't show up in the FOREIGN category. It just seems logical that I could add a band, select what categories I want that band in, and once I save the entry the band would show up in each of the categories as well. I've tried to type out all the details a few times and it seems it would be easier to attach a PDF of the screen shots for the sake of simplicity - and also someone may see some setting that I'm overlooking.I do appreciate those that could get me on the right track with this. music_multiple_categories_pwire.pdf Link to comment Share on other sites More sharing options...
kongondo Posted February 16, 2016 Share Posted February 16, 2016 (edited) I do appreciate those that could get me on the right track with this. Hi @holmescreek, Welcome to ProcessWire and the forums. You might want to have a read here first about various approaches to categorising site content. I have only had a quick glance at the PDF. I notice you are creating the ABBA page directly under POP then also having the possibility to select POP (the parent page) within ABBA. That's not the 'usual' way we got about this. What would work best is something like this (page tree): Genres (template genres) Pop (template genre) Foreign Rock Artists (template artists) ABBA (template artist) U2 Rolling Stones Then, in the template artist (for individual artists), add a page field of type multiple, called, for example, genres. In the page field genres, in template of selectable pages, set that to 'genre'. Then, in your artist pages, say when editing ABBA, you can choose all the genres you want for the band, e.g. 'Foreign' and 'Pop'. In the front-end end you can then do something like: // grab all pop bands (if many, you may want to place a limit and use pagination) $pop = $pages->get('/genres/pop/'); $artists = $pages->find("template=artist, genres=$pop"); // or, if users are viewing the POP page $artists = $pages->find("template=artist, genres=$page"); Of course, it is possible to search for multiple genres in a single query. See the selectors' docs here. This type of organisation keeps duplicity to a minimum. Edited February 16, 2016 by kongondo 4 Link to comment Share on other sites More sharing options...
BitPoet Posted February 16, 2016 Share Posted February 16, 2016 You're mixing two concepts here: First, the native parent-child relationship that PW provides. ABBA is a child of the Pop page (category). This is what the backend shows and every page can only have one parent. Second, you have relationships through page fields. This is completely structure-agnostic. You're actually making things a little complicated by placing the artists underneath a category. Easier would be to have a page "artists" underneath "music" with its own template and under which you have all artists, no matter what category they belong to, and simply set all the categories for the artists like you already do. Presentation of the relationship for the frontend happens in your PHP template file for music-genres, where you get all the artists for the category with a selector like $artists = $pages->get("template=music-artist, music_genre_types={$page->id}"); instead of calling $page->children. You could mix both concepts and merge $page->children with the result of the selector above, then your current approach would still work. 2 Link to comment Share on other sites More sharing options...
John W. Posted February 16, 2016 Author Share Posted February 16, 2016 Hi @holmescreek, Welcome to ProcessWire and the forums. You might want to have a read here first about various approaches to categorising site content. Thanks for the greetings! I threw your suggestion together and it works well (screenshot attached). I did nearly the same thing yesterday, separating genres from artists. One twist, though, something I expect from one client in the near future. Second question - In the back-end I have a particular client that likes to drag and drop artists in random positions in a specific genre. For instance, he likes to arrange artists in what he deems their importance is to him. So, the artist 'ABBA' might show up as the first artist listed when you list the ROCK genre but it if I fetch all the artists out of FOREIGN he may have ABBA anywhere, such as the last in the list. By separating genres and artists - as you described - the first thing that comes to mind is adding a 'Sort Priority' field for each artist, however, the problem therein is that no matter what genre is listed that priority would take precedence when any genra listing is displayed. P.S. Bookmarked that link, some goodness to read there. Thanks! You're actually making things a little complicated by placing the artists underneath a category. Easier would be to have a page "artists" underneath "music" with its own template and under which you have all artists, no matter what category they belong to, and simply set all the categories for the artists like you already do. Thanks. Think I've almost got my head wrapped around it between you and kongondo's info. Link to comment Share on other sites More sharing options...
horst Posted February 16, 2016 Share Posted February 16, 2016 If I understand right, you need to set the sort order for all children under artists to manual drag-n-drop. This can be done under pages -> artists -> edit -> children -> Sort Settings. Then, in your tempklates / API, you add to your selector sort=sort, // example with manual sort order $children = $pages->find("parent=/artists/, sort=sort, limit=10"); Link to comment Share on other sites More sharing options...
John W. Posted February 16, 2016 Author Share Posted February 16, 2016 If I understand right, you need to set the sort order for all children under artists to manual drag-n-drop. This can be done under pages -> artists -> edit -> children -> Sort Settings. Then, in your tempklates / API, you add to your selector sort=sort, // example with manual sort order $children = $pages->find("parent=/artists/, sort=sort, limit=10"); Thanks. But, that's not what I'm shooting for. The above would just allow the end user to manually sort the artist names under artists. Link to comment Share on other sites More sharing options...
BitPoet Posted February 16, 2016 Share Posted February 16, 2016 If you want to sort the artists differently for each genre, you'll probably have to reverse the logic and add an "artists" page field to the genre template and put the artists there. Each page then keeps its own sort order for its field contents, so your client can sort the artists however he wants. It doesn't scale as well though if you have many artists. 2 Link to comment Share on other sites More sharing options...
John W. Posted February 16, 2016 Author Share Posted February 16, 2016 What would work best is something like this (page tree): Genres (template genres) Pop (template genre) Foreign Rock Artists (template artists) ABBA (template artist) U2 Rolling Stones Then, in the template artist (for individual artists), add a page field of type multiple, called, for example, genres. In the page field genres, in template of selectable pages, set that to 'genre'. Then, in your artist pages, say when editing ABBA, you can choose all the genres you want for the band, e.g. 'Foreign' and 'Pop'. In the front-end end you can then do something like: On the second question regarding placing artists under various genres and allowing the end user to sort the artists for each unique genre I think I got it. At lunch, I got the bright idea of implementing the above, but, reversing the page field implementation. In other words, instead of going to artists->artist and selecting the genres they belong to I did the opposite. I set up where you could go to genres->rock and select the artists -- using AsmSelect the user can now manually re-arrange the list of artists that is unique to each genre. So now the user can manually sort artists differently under each genre. example: music->ROCK ABBA ZZ-TOP JENNIFER LOPEZ ROLLING STONES JOAN JET BRITTANY SPEARS music->POP JENNIFER LOPEZ BRITTANY SPEARS ABBA If you want to sort the artists differently for each genre, you'll probably have to reverse the logic and add an "artists" page field to the genre template and put the artists there. Each page then keeps its own sort order for its field contents, so your client can sort the artists however he wants. It doesn't scale as well though if you have many artists. Thanks, I thought about the same thing over lunch (above) -- was doing my post about this as you were posting the idea. 2 Link to comment Share on other sites More sharing options...
John W. Posted February 16, 2016 Author Share Posted February 16, 2016 Thank's everyone for your help! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now