<div class="cat">
    <?php $year = null; ?>
    <?php foreach ($data as $row): ?>
    <?php
        if ($year != $row['year']) {
            $year = $row['year'];
            echo '<div class="cat-year">'.$year.'</div>';
        }
    ?>
    <div class="cat-story">
        <a href="<?php echo htmlspecialchars($row['link']) ?>"><?php echo $row['title'] ?></a>
    </div>
    <?php endforeach; ?>
</div>

<?php if (!empty($pager)): ?>
<?php echo $pager; ?> 
<?php endif; ?>