Jump to content

Echo only Tags on page


Peter Knight
 Share

Recommended Posts

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

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

×
×
  • Create New...