Jump to content

Render Tags on page from InputfieldTextTags


Troost
 Share

Recommended Posts

Hi all,

I'm working on a project where I would like to use something like a tag-cloud. Since I couldn't find any (recent) module for this. I decided to use the InputfieldTextTags to let the admin give tags on the article/item. Now I want to echo the tags (from every tag field in the backend) in the sidebar. (So, it echo's the tags from page X, and the tags from page Y) I want to show them random with a limit of 10.

With some searching around the forum I found this code

<?php
	foreach($page->fields as $field) {
	    $fieldValue = $page->get($field->tags);
	    echo $field;
	    
	    foreach($fieldValue as $innerPage) { 
	        foreach($innerPage->fields as $innerPageField) {
	            $innerPageFieldValue = $innerPage->get($innerPageField->tags);
	            echo $innerPageFieldValue;
	        	}
	    	}
	} 
?>

But the only thing which is echoing right now is just the word 'title' (which is not a tag on the website).

Then I found this, but that didn't work either

<?php $results = $pages->find("tags={$page->tags}")->shuffle(); ?>


Can someone help me out to echo the tags in the sidebar, and just to be sure, is this the way to work with tags? Or is there another way which is better to work with?

Thanks in advance!
 

Link to comment
Share on other sites

You need to get $inputfieldTextTags from the field itself:

$inputfield = $page->getInputfield('tags_field');
$list = $inputfield->getTagsList(true);
foreach($list as $item){
   // echo tags ?
}

 

  • Like 2
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...