Categorizing/tagging content
#2
Posted 02 February 2011 - 03:35 PM
$matches = $pages->find("tag*=something"); // where 'something' is a tag
If you want predefined tags, then I would use a page reference fieldtype to associate a group of pages as tags. Populate the pages with their name or title field as your tag. Then use a multiple selection field like asmSelect to allow selection of the tags/categories. To find pages matching a given tag, you'd do this:
$tag = $pages->get("/tags/something/");
$matches = $pages->find("title=$tag");
#3
Posted 02 February 2011 - 06:42 PM
England
London
Manchester
Birmingham
Scotland
Glasgow
Edinburgh
And then loop through them to produce some info from pages linked to these categories/tags in a nested list under each category title...
England
page-1-title + page-1-img
page-2-title + page-2-img
Manchester
page-3-title + page-3-img
etc. etc.
So end result something like the list on the left of http://massagenewzea...nd-a-therapist/
#4
Posted 02 February 2011 - 10:01 PM
#5
Posted 03 February 2011 - 07:19 PM
#6
Posted 03 February 2011 - 09:58 PM
If you are doing something with free tagging, then I would use url segments. Lets say you've got a free tagging field called "tags", and it's just a textarea with one or more tags. You might setup a template called "tags" and on a page called "/tags/". Accessing /tags/something/ in your browser should list all pages that match the tag "something". To do that, first turn on URL segments in your template (Admin > Setup > Templates > Advanced > URL Segments). Then, in your template, your code might look something like this:
<?php
if($tag = $sanitizer->selectorValue($input->urlSegment1)) {
$matches = $pages->find("tags*=$tag");
echo $matches->render(); // or loop through and print on your own
}
For pre-defined categories using page referencs, I think that asmSelect is a good input field to use for selection. However, if you need to be able to select pages in a hierarchy (like category or subcategory with the same field) then I think the "page list select multiple" is a good solution, because it enables you to select pages in a hierarchy rather than in one level. You could also use any of the other multi select input fields and use the template as the base for selection rather than the parent.
ProcessWire is a couple months old, and Drupal has been around since 2001, so we're not going to have the same level of features in some areas. But if you think Drupal is better at this than PW2, describe further, and more specifically, so that I can make sure we get PW2 one step ahead. When it comes to working with these kind of data relationships, I believe PW2 is better than Drupal on the back-end, so I want to make sure I provide enough front-end simplicity to provide and prove that.
thanks,
Ryan
#8
Posted 06 February 2011 - 02:32 PM
#9
Posted 06 February 2011 - 07:42 PM
#10
Posted 28 July 2011 - 11:45 AM
#11
Posted 28 July 2011 - 12:35 PM
The tree hierarchy defines the primary home of content. It does not define all of it's other categories, connections or relations to other nodes (pages) in the tree or other pages of the same type. This is what page references and templates are for. So in your case, I would suggest the following structure. I'm assuming that there are multiple product types, in addition to toys.
/products/toys/ /products/toys/some-toy/ /categories/wooden/ /categories/some-category/ /materials/wood/ /materials/brick/ /materials/straw/
Create page relations on your product template called "categories" and "materials" and set them to choose from the relevant parents. Now you can deduce any number of other relations on the fly, like:
/categories/wooden/toys/
But no need to literally create that page, because the context can already be determined from the existing relations. So your 'category' template code might look like this:
<?php
if($input->urlSegment1) {
// there is an extra component on the URL that doesn't resolve to a page, like /categories/wooden/toys
// so we assume they are adding a product type filter
$name = $sanitizer->pageName($input->urlSegment1);
$type = $pages->get("/products/$name/");
$products = $type->children("category=$page");
} else {
// just grab all products in this category
$type = new NullPage();
$products = $pages->find("template=product, category=$page");
}
echo "<h1>Products in category: {$page->title}</h1>";
if($type->id) echo "<h2>With type: {$type->title}</h2>";
foreach($products as $product) {
echo "<li><a href='{$product->url}'>{$product->title}</a></li>";
}
#13
Posted 30 July 2011 - 02:33 AM
#14
Posted 30 July 2011 - 04:13 AM
Actually for me that was very interesting to see and compare to 2.0. There is much more "everything" in 1.0, and comparing these two really shows that great design is always to make things simple. Separating fieldtypes from inputfields: brilliant. Hiding fieldgroups: brilliant. Although it seems that 1.0 was already pretty simple cms (considering the flexibility).
PS: Ryan, you have great and very clear style on your videos!
#15
Posted 30 July 2011 - 04:31 AM
PS: Ryan, you have great and very clear style on your videos!
In no particular order: Designer, developer, composer, movie star
#16
Posted 30 July 2011 - 05:34 AM
In no particular order: Designer, developer, composer, mov-e star
Yep. But have you heard that he can build skyscrapers with just bare hands?
#17
Posted 30 July 2011 - 03:14 PM
#18
Posted 31 July 2011 - 01:38 AM
#19
Posted 13 September 2011 - 04:31 AM
I'm a bit stumped with getting categories to work for me in PW.
Say my page setup is like this:
Home
- Portfolio
-- work item
-- work item
-- work item etc
- Blog
-- Blog item
-- Blog item
-- Blog item etc
- Categories
-- Work
--- cat_name
--- cat_name
--- cat_name etc
-- Blog
--- cat_name
--- cat_name
--- cat_name etc
In my work and blog pages I have a field called categories with each parent being the Work and Blog subpages in Categories. I can add a category (via pageselect) to a work or blog entry no problems.
What I can't work out is how to get a list of categories and filter work or blog items on those categories.
Can I have: .com/work/categories/design - do I need to then move my Categories/Work tree beneath my Portfolio tree?
or does it need to be: .com/categories/work/design/
Confusedly yours,
Marty
#20
Posted 13 September 2011 - 08:02 AM
If I'm following your right, it sounds like you want to be able to list the categories in your Portfolio section even though they don't technically live there. That's no problem. Just edit your Portfolio index template, click on the URLs tab and tell it to allow URL segments.
Now you can have our Portfolio index template look for categories and display items from them:
<?php
if($input->urlSegment1 == 'categories') {
if($input->urlSegment2) {
// example: /categories/work/architects/
// category specified, list items in category:
$name = $sanitizer->pageName($input->urlSegment2);
$category = $pages->get("/categories/work/$name/");
if($category->id) {
// valid category, list items in it
echo $page->children("categories=$category")->render();
} else {
// unknown category
echo "<p>I don't know that category.</p>";
}
} else {
// list categories
echo $pages->get('/categories/work/')->children()->render();
}
} else {
// list all portfolio items
echo $page->children()->render();
}
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













