Peter Knight Posted September 26, 2014 Share Posted September 26, 2014 I've followed a tutorial on setting up tags and have a tag field as follows: type=page allow new pages to be created from field=yes input field type - Asmselect Using the following on my template, I can output all the tags on my site <H3>Tags</H3> <?php $tags = $pages->get("/tags/")->children->find("sort=title"); echo "<ul>"; foreach($tags as $tag){ //iterate over each tag echo "<li><a href='{$tag->url}'>{$tag->title}</a></li>"; // and generate link to that page } echo "</ul>"; ?> What I'd like to do is echo only the tags used on the page being displayed. I thought the trick was to use $page instead of $pages as follows <?php $page->get("tags"); foreach($tags as $tag){ //iterate over each tag echo "<a href='{$tag->url}'>{$tag->title}</a></li>"; // and generate link to that page } ?> No joy. I think I know why. it's because my field called tags has a separate page for each tag so I probably need to use something like $page->get"tags" ->children Obviously thats not realy php but my literal interpretation. Just wondering if I'm on the right track and where I am going wrong. Link to comment Share on other sites More sharing options...
adrian Posted September 26, 2014 Share Posted September 26, 2014 I am guessing you are using a page field on each page to determine which of the tags children are used? If so then you need to: foreach($page->tagsfield as $tag){ echo "<a href='{$tag->url}'>{$tag->title}</a></li>"; } 1 Link to comment Share on other sites More sharing options...
Peter Knight Posted September 26, 2014 Author Share Posted September 26, 2014 Thanks Adrian. Hoping I'll eventually get "there" :-/ 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