Pyro CMS Plugin

Just been messing around with PyroCMS (version 2), a cms built on codeigniter. I couldn't find a function/plugin within the core install that allows you to switch between classes for the purpose of setting up columns.

So I've thrown a quick one together. so create a plugin called switcher (You can call it anything you like) in site/addons/shared_addons/plugins/switcher.php

<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Switcher Plugin
 *
 * usage {{ switcher:class_row }}
 * Note:
 * Each class is separated by the pipe key and no spaces.
 * No limit to the number of alternate classes.
 *
 * @package        PyroCMS
 * @author        Kevin Phillips
 * @copyright    Copyright (c) Kevin Phillips
 * @link http://www.kevinphillips.co.nz
 * @param string
 * @return string
 */
class Plugin_Switcher extends Plugin {

    function class_row()
    {
        $classes = $this->attribute('class');

        $values = explode('|', $classes);

        // Uses Codeigniter String Helper function alternator();
        if( ! function_exists('alternator'))
        {
            $CI =& get_instance();
            $CI->load->helper('string');
        }
        return call_user_func_array('alternator', $values);
    }
}

so to use this plugin just add the switcher to which ever element you want to add a ccs class to.

<p>
    {{ blog:posts limit=&quot;5&quot; order-by=&quot;title&quot;
order-dir=&quot;desc&quot; url=&quot;news&quot; }}

<divleft_col|center_col|right_col" }}">

<h2>     {{ title }}</h2>
<p>     {{ intro }} <a href="{{ url }}"
    title="Read more about: {{ title }}">Read more</a></p>
<p>Written by: <a href="/users/profile/{{ author_id }}">
  {{ author_name }}</a></p> <p>
</div>     
{{ /blog:posts }}</p>

Now your div's will have the class attached to them as the blog loops. You can download the code from GitHub

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments

Copywrite © 2017 Kevin Phillips All rights are reserved.

Proudly supporting opensource software