Topic: Solved: Limit textlength of linknames
Consider this navigation list in a sidebar:
<?php $last_articles = $this->children(array()); ?>
<ul>
<?php foreach ($last_articles as $article): ?>
<li class="slide"<?php echo (url_start_with($article->url)) ? ' id="current_sub"': null; ?>><?php echo $article->link(); ?></li>
<?php endforeach; ?>
</ul>Now I like to limit the textlength of every linkname (not the url) to be max. 32 chars long.
I found out after some playing with the code, this is my solution:
<?php $last_articles = $this->children(array('order' => 'id DESC')); ?>
<ol>
<?php foreach ($last_articles as $article): ?>
<?php
$limit = 32;
$str = $article->title;
if (strlen($str) > $limit)
$str = substr($str,0,$limit)
?>
<li class="slide"<?php echo (url_start_with($article->url)) ? ' id="current_sub"': null; ?>><?php echo $article->link($str); ?></li>
<?php endforeach; ?>
</ol>Last edited by Fortron (2010-09-04 01:37)

