Hi, I want to use contemplate to provide clickable taxonomy links, but I want this to be set up as a views argument, rather than the teaser output you get when clicking on automatically generated taxonomy links. So rather than getting the teaser list you get taken to a views page filtered by the term you clicked on.

For the following examples $field_distribution_0 contains: Paraguay, Brazil, now if you just print this it will output the code:

Brazil<br />
Paraguay<br />

So I want to edit this to remove the line breaks and change the way the links work.

	<?php
		foreach ((array)$field_distribution_0 as $item) {
      		$print=$item['view'];
      		$cleanedprint=str_replace("<br />",", ",$print);
	  	print "<a href='/browse_distribution/$cleanedprint'>".$cleanedprint."</a>";
    }
?>

Now I thought this would remove the line breaks and add an a href link to each of the terms, but it just added a single link to the entire list of terms and $cleanedprint became:

<a href="/browse_distribution/ParaguayBrazil">ParaguayBrazil</a>

So I had to do it a rather long winded way:

<?php
$depth=count($field_distribution_0);
$location=explode("<br />",$field_distribution_0[0]['view']);
$count = 0;
while ($count<=$depth){
                print "<a href='/browse_distribution/$location[$count]'>".$location[$count]."</a> ";
                $count = $count + 1;
}
?>

Is there a better/easier/quicker way of doing this? I'm just a bit confused as I thought that it would be stored as an associative array, but it seems to be one long string as a single key in the array?

Comments

matthew_ellis24’s picture

also that doesn't work as $depth always equals 1 because the array values all seem to be stored as a single string. So you need to count the depth of the exploded array and make sure you subtract one from the depth (as the array values start at 0 not 1). So you end up with

<?php
$depth = 0;
$count = 0;
$location=explode("<br />",$field_distribution_0[0]['view']);
$depth=count($location);
     while ($count<=$depth-1){
         print "<a href='/browse_distribution/$location[$count]'>".$location[$count]."</a> ";
         $count = $count + 1;
     }
?>

Surely there's an easier way to do it?