a-ok Posted December 5, 2014 Share Posted December 5, 2014 If I am implementing a 'free tagging field', which is explained by @ryan here > https://processwire.com/talk/topic/71-categorizingtagging-content/ is there any way to do this for more than one word (for example if a tag I entered is 'green energy') So, I have a tag.php template which uses something like: <?php if ( $tag = $sanitizer->selectorValue($input->urlSegment1) ) : ?> <?php $matches = $pages->find("tags*=$tag"); ?> <?php foreach ($matches as $match) : ?> <?php endforeach; ?> <?php endif; ?> This allows me, using url segments, to do: /tags/green and the results with a tag 'green', would come up. But how would I do it for something like 'green energy', so /tags/green+energy or /tags/green-energy... Currently my free tagging field is just a text field, but I could make this into a repeater, for example, if it helps this situation. Thanks in advance Link to comment Share on other sites More sharing options...
renobird Posted December 5, 2014 Share Posted December 5, 2014 You could use an autocomplete pageField for the tags. That way existing tags are available across all pages using the field. Check the "allow new pages to be created from this field" option. The end result, is that your tags are now page references that you can search against by the sanitized name field. 2 Link to comment Share on other sites More sharing options...
a-ok Posted December 9, 2014 Author Share Posted December 9, 2014 Hi @renobird, thanks for the help and sorry for the slow response. I don't quite think I understand... essentially I'm wondering if you can search by tag if the 'tag' is more than one word. So, if it's one word, http://www.domain.com/tags/green, for example, works... but if it's two or more, I'm not sure how to word it http://www.domain.com/tags/green-energy or http://www.domain.com/tags/green+energy etc. I think I kind of understand, but couldn't find the 'allow new pages to be created from this field' checkbox. Thanks in advance. Link to comment Share on other sites More sharing options...
a-ok Posted December 9, 2014 Author Share Posted December 9, 2014 Oh, and my 'tags' aren't pages... it's just a text field Link to comment Share on other sites More sharing options...
renobird Posted December 9, 2014 Share Posted December 9, 2014 Hi Richard, If you use the pageField method, then every "tag" creates a page that has a unique name. Example (green-energy, shark-sandwiches, turtle-soup). The autocomplete field presents the user with the page title, so they would select tags like (Green Energy, Shark Sandwiches, Turtle Soup). Same applies for adding new tags. Now you can use UrlSegments to find pages with your multi-word tags because they will be in a format like /domain/tags/green-energy/ 4 Link to comment Share on other sites More sharing options...
a-ok Posted December 9, 2014 Author Share Posted December 9, 2014 @renobird Ah right yes, I get you. I started writing a reply... but then I suddenly got it. Okay great... I will try this. Most appreciated! Link to comment Share on other sites More sharing options...
a-ok Posted December 9, 2014 Author Share Posted December 9, 2014 @renobird Hi, sorry... quick thing... if I originally used: <?php if ( $tag = $sanitizer->selectorValue($input->urlSegment1) ) : ?> <?php $matches = $pages->find("tags*=$tag"); ?> How would I use urlSegment1 for this new setup you suggested? I thought this might've worked... <?php if ( $tag = $sanitizer->pageName($input->urlSegment1) ) : ?> <?php $matches = $pages->find('/tags/$tag/'); ?> Many thanks... Link to comment Share on other sites More sharing options...
Jan Romero Posted December 9, 2014 Share Posted December 9, 2014 $variables are only resolved when inside "double quotes". With the 'single quotes', $pages->find() will always look for /tags/$tag/, never /tag/green-energy/, etc.. Might just be a typo in your post, but I thought I’d mention it. Link to comment Share on other sites More sharing options...
a-ok Posted December 9, 2014 Author Share Posted December 9, 2014 @Jan Thanks for that... makes sense! Unfortunately this doesn't seem to solve the issue as <?php if ( $tag = $sanitizer->pageName($input->urlSegment1) ) : ?> doesn't seem to be returning anything on /tags/green-energy for example... Link to comment Share on other sites More sharing options...
a-ok Posted December 9, 2014 Author Share Posted December 9, 2014 Worked it out... <?php $tag = $page->name; ?> <?php $matches = $pages->find("tags=$tag"); ?> <?php foreach ($matches as $match) : ?> 2 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