Back to Tutorials

Making categories with Advanced Find plugin

  • on 21/09/2010 (updated on 12/03/2014)
  • in howto.

Wake up call on the Wolf official forum gave me an idea (read: David suggested) for new article on how to make categories in Wolf CMS. There are couple of ways to make categories, with Tags and Tagger plugin (this is how people usually do) or with Pages and Advanced find plugin.

Making categories in WolfCMS

In this tutorial we’ll stick to the second one, based on the forum topic Blog?.

Before we start, you’ll need to download Advanced Find plugin made by Tyler Beckett, upload and unpack it to your server under wolf/plugins/ directory and enable it in Administration area.

For the purpose of this tutorial I will use this site structure and code, but you can adopt/change it as it fits your needs

Defining Category tree under Pages area

First we need to make our categories, so let’s do that.

Mine parent category container is named Articles (you can name it Blog, News etc.), and has 4 children; Basic, Advanced, Design and Reviews, which are my categories.

WolfCMS categories

After that, you can make one test article per category for testing purposes.

Note: You can make only one category with all the code necessary below, then just copy and reorder that page in admin area, and add it into adv_find array.

Display articles with teaser from all categories on Home page

It doesn’t have to be on Home page, you can display it under Blog or News page as well, the code is the same

I use David’s Single Page-part technique for displaying teasers with Read more link as I find it easier to work with.

So let us begin with selection of our categories. We have to put our new made categories in array, order it to be sorted by published date and set limit of last 5 articles.

Navigate and do:

  • Go to Admin area / Pages
  • Open Home page
  • Set Filter to “none”
  • Paste 2 below snippets (advanced array and foreach loop)
<?php $articles = adv_find(array('/articles/basic/','/articles/advanced/','/articles/design/','/articles/reviews/'),array('order'=>'published_on DESC', 'limit'=>5)); ?>

Note: Advanced find plugin doesn’t allow limit less then 2 articles so keep that in mind. See Tyler’s comment below.

Next step is classic Wolf foreach loop:

<?php foreach ($articles as $article): ?>
<div id="article"><!-- article -->
<!-- OUR TITLE -->
<h1><?php echo $article->link(); ?></h1>
<!-- METADATA -->
<p class="info"><span class="date"><?php echo $article->date('%d.%m.%Y'); ?></span> | Topic: <span class="topic"><?php echo $article->parent->link(); ?></span> | Tags: <span class="tags"><?php echo tag_links($article->tags()); ?></span></p>
<!-- DAVID'S SINGLE PAGE TEASER -->
<?php if (($more_pos = strpos($article->content(), '<!--more-->')) === false ) {
  // "more" trigger NOT found, so just echo content
  echo $article->content();
} else {
  // "more" trigger IS found, so echo only teaser and add link to whole article
  echo substr($article->content(), 0, $more_pos);
  echo '</p><p class="readmore">'. $article->link('Read more . . .') .'</p>';
} ?>
</div><!-- /article -->
<?php endforeach; ?>

The metadata paragraph is optional but for Tags part you’ll need Tagger plugin installed or you’ll get bunch of errors.

Note: Don’t forget to add both code snippets in this order!

Listing articles under each category

The last step is to list articles under each category.

On this site I decided to make a small description with number of all articles under certain category and list them with title, date, tags and number of comments.

WolfCMS categories listing

Navigate and do:

  • In Admin area under Pages, go to your first category (in this case “Advanced”)
  • set Filter to “none”
  • Paste below code snippet and Save
<div id="article">
    <h2>Current topic: <?php echo $this->title(); ?></h2>
    <div id="intro">
    <p>This topic covers some advanced uses of Wolf CMS and is intended for <a href="/articles/how-to/" title="How To">non-beginners</a>  <br />
    There <?php if ($this->childrenCount() !=1){ echo 'are'; } else { echo 'is'; } ?> <strong><?php echo $this->childrenCount(); ?></strong> article<?php if ($this->childrenCount() !=1){ echo 's'; } ?> in this topic.</p>
    </div>
<?php $last_articles = $this->children(array('order'=>'page.created_on DESC')); ?>
<?php foreach ($last_articles as $article): ?>
    <div id="categorylisting">
    <h2><?php echo $article->link(); ?></h2>
    <p class="listinfo">Published on <?php echo $article->date('%d.%m.%Y'); ?> <span class="green">&lowast;</span> Tags: <?php echo join(', ', $article->tags()); ?> <span class="green">&lowast;</span> <?php echo $num_comments = comments_count($article); ?></strong> comment<?php if ($num_comments != 1) { echo 's'; } ?></p>
    <!-- DAVID'S TEASER FOR READ MORE LINK -->
    </div>
<?php endforeach; ?>
</div>

If you want display teaser here as well, then just paste David’s code below commented area.

That should do it!

Note: If you’ve renamed your parent container (here is “Articles”) into Blog or something else, then you have to change it in code snippets too.

blog comments powered by Disqus