esspea Posted July 12, 2021 Share Posted July 12, 2021 Hello, As my first project I chose to create a recipe page. Not really inventing the wheel, I know, but It's a fun project and there are a few learning points. Now I have set up the database and I can create recipes and they look ok so that's kinda sorted. What I want to do next is categorizing. The "recipe" template has a page reference field called category where each recipe can get categorized by more than one category and I want to be able to sort the recipes by category. I've been fiddling about with find() but not really gotten it to work properly, can someone please give me a little push, an idea to get me on the right track. Thank you, Snorri Link to comment Share on other sites More sharing options...
MarkE Posted July 12, 2021 Share Posted July 12, 2021 Depending on what you are trying to achieve, one approach is to have a page ref field in the category template to ref back to the recipes, then use the ConnectPageFields module to keep them in sync. That then gives you lots of options for viewing and updating. Link to comment Share on other sites More sharing options...
BillH Posted July 12, 2021 Share Posted July 12, 2021 If you create a page reference field named 'recipe_category' and want to find everything in the category 'soup', you could do something like this: $categoryPage = $pages->get("name=soups"); $soups = $pages->find("template=recipes, recipe_category=$categoryPage"); Alternatively, if you could use a select options field (easier to set up, but less flexible and harder to change anything, so usually page reference fields are better in the long run): $soups = $pages->find("template=recipes, recipe_category.title=soups"); Link to comment Share on other sites More sharing options...
esspea Posted July 13, 2021 Author Share Posted July 13, 2021 Thank you Bill and Mark, you've been most helpfull. 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