Jump to content

How to find (list) all pages matching tag


Mijo
 Share

Recommended Posts

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

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.

  • Like 2
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...