Mijo Posted January 17, 2018 Share Posted January 17, 2018 Hello, I'm trying to get all pages that are using specific tag, for example I have page that uses tag sport, and then when I go to that specific url : example.com/tag/sport I want to list all pages that using sport tag. I'm using page reference like on this topic (link), and so far a get list all tags with: foreach($page->tag as $item) { echo "<li><a href='$item->url'>$item->title</a></li>"; } How can I get list of all pages that are using specific tag? For example on tag template. Thank you all. Link to comment Share on other sites More sharing options...
DaveP Posted January 17, 2018 Share Posted January 17, 2018 Is this any help (from a working site) <?php namespace ProcessWire; if(!$input->urlSegment1) throw new Wire404Exception(); $tag = $sanitizer->name($input->urlSegment1); $tagtitle = $pages->get("template=tag,name=$tag")->title; if(!$tagtitle) throw new Wire404Exception(); In your example this would be from /tag/ template, which is set to use urlSegments. 2 Link to comment Share on other sites More sharing options...
kongondo Posted January 17, 2018 Share Posted January 17, 2018 Or...if sport is the tag page itself (i.e. it is an item in the page reference field)...then something like this... $sportsPages = $pages->find("tags_page_field=$page");// @note: add a limit if lots of tags and paginate Link to comment Share on other sites More sharing options...
Mijo Posted January 17, 2018 Author Share Posted January 17, 2018 2 hours ago, DaveP said: Is this any help (from a working site) <?php namespace ProcessWire; if(!$input->urlSegment1) throw new Wire404Exception(); $tag = $sanitizer->name($input->urlSegment1); $tagtitle = $pages->get("template=tag,name=$tag")->title; if(!$tagtitle) throw new Wire404Exception(); In your example this would be from /tag/ template, which is set to use urlSegments. Thank you works like charm. 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