Kevin Phillips is a web developer for Devol and LiveHost WebHosting
Pyro CMS Plugin
Submitted by kevin on Thu, 12/01/2011 - 11:12
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://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="5" order-by="title" order-dir="desc" url="news" }} <div class="{{ switcher:class_row class="left_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
Add new comment