For the life of me, I can’t figure out how to turn the last segment of the navtrail OFF. I don’t want the last segment to be a link. I tried returning the value of the loop count ($i) and the $len, or number of SEGS, and they never match. I’m assuming that if they match, the last link turns off. This plugin is very close to what I need, as the structure of the site I’m on is rather arbitrary, so I sort of need to run the breadcrumb off the url segments.
Sample output:
Home > Service > Services 1 4 > Article 2 4 > Article Title 3 4
The first number is the loop count (I think) and the second is the results from $len = count($IN->SEGS);. I’m not sure that helps, but It seems like there should be some way to know you’re on the last segment and not make that a link.
And while we’re at it, is there an easy way (preg_replace or some thing like that…) to ignore certain segments? The only real arbitrary segment in my site is “Article”. I’d like the above trail to look like this, ideally:
Home > Service > Services > Article Title
In case you don’t have the plugin handy, here are relevant pieces. In the second one, I don’t feel like that last else statement ever really does anything.
function navTrail()
{
global $IN;
$len = count($IN->SEGS);
for ($i=1; $i<=$len; $i++)
{
if ($IN->SEGS[$i])
{
$this->sections[] = $IN->SEGS[$i];
}
}
}
The main loop is here. I’ve picked my way through PHP before, but this one is just giving me fits.
if(trim($this->sections[0]) != trim($is_default))
{
$this->return_data = '<a href="http://.$_SERVERSCRIPT_NAME">.'"]Home</a>'.DELIMIT;
$path = $_SERVER['SCRIPT_NAME']."/".$this->sections[0];
$this->return_data .= '<a href="http://.$path.">'.$this->format($this->sections[0]);_ _ $len = count($this->sections);_ for ($i=1; $i<$len; ++$i)_ {_ if(!is_numeric($this->sections[$i]))_ {_ $path .= "/".$this->sections[$i];_ if(isset($this->sections[$i+1]) and is_numeric($this->sections[$i+1]))_ {_ $path .= "/".$this->sections[$i+1];_ $this->return_data .= DELIMIT.'<a href="'.$path.'">'.$this->format($this->sections[$i]).'</a>';
}
else
{
$this->return_data .= DELIMIT.'<a href="http://.$path.">'.$this->format($this->sections[$i]).'</a>';
}
}
}
}
}
return $this->return_data;
}
Maybe someone could at least explain what a couple of these lines are doing in plain language so I can tweak it myself?
if(isset($this->sections[$i+1]) and is_numeric($this->sections[$i+1]))
What is that? If there is another section? Why “is_numeric”?
Thanks for any help.
Masuga,
Who made this plugin? Its always best to try the author first. They know their own code. At least we certainly hope they do.
If you can’t get anything out of them, I’m guess you just need to determine the last item in the array: $this->sections and then treat it differently than the others.
You already know how many items are in the array from the $len variable. So you have the information you need to add an additional variable to figure out when the last item in the array is being processed.
Jamie
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.