Truncate

This plugin allows you to make automated excerpts on your site with simple call. It is a simple function and can go into snippet if you don’t want to call it like a plugin, but this way it’s clutter free and works like a charm :).

Advantages of this plugin:

Installation

This one is classic Wolf:

  1. download plugin
  2. unzip it under “/wolf/plugins/” directory
  3. rename its folder to “truncate”
  4. go to Administration->Plugins
  5. enable plugin

Simple as that!

Usage

You have to call function truncate where you want to make your excerpts and pass it to variable. Function itself can take these arguments:

<?php truncate(CONTENT, LIMIT, SUFFIX); ?>

If you want to disable “suffix” then you just add “” (empty quotes) on third place.

Basically, you call it like this:

<?php
$myarticles = truncate($article->content(), 250, "..."); 
echo $myarticles;
?>

Example code is used for /articles tree

1. Simple example (default):

<?php $last_articles = $this->children(array('limit'=>5, 'order'=>'page.created_on DESC')); ?>
<?php foreach ($last_articles as $article): ?>
<div class="entry">
<h3><?php echo $article->link($article->title); ?></h3>
<?php
$myarticles = truncate($article->content(), 300, "...");
echo $myarticles;
?>
</div>
<?php endforeach; ?>

And this is how your excerpts will look like by default:

Default truncate

2. With Read more link

<?php $last_articles = $this->children(array('limit'=>5, 'order'=>'page.created_on DESC')); ?>
<?php foreach ($last_articles as $article): ?>
<div class="entry">
<h3><?php echo $article->link($article->title); ?></h3>
<?php
$myarticles = truncate($article->content(), 300, "");  
echo $myarticles;
echo '<p>'.$article->link('Read more...').'</p>';
?>
</div>
<?php endforeach; ?>

The “p” is here just for readability and can be styled differently with css.

And it looks like this:

Truncate with read more link

Changelog

Version 0.0.2

Version 0.0.1