Skip to content

Instantly share code, notes, and snippets.

@zgordon
Created May 14, 2011 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zgordon/971569 to your computer and use it in GitHub Desktop.
Save zgordon/971569 to your computer and use it in GitHub Desktop.
Child Cat Count - ExpressionEngine Plugin
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$plugin_info = array(
'pi_name' => 'Child Category Count',
'pi_version' =>'1.0',
'pi_author' =>'Zac Gordon',
'pi_author_url' => 'http://www.wideskyweb.com/expressionengine',
'pi_description' => 'Returns number of child categories.',
'pi_usage' => Childcatcount::usage()
);
class Childcatcount {
var $return_data = '';
function Childcatcount()
{
$this->EE =& get_instance();
//Get parameters
$cat_url_title = $this->EE->TMPL->fetch_param('cat_url_title');
$group_id = $this->EE->TMPL->fetch_param('group_id');
$count = 0;
//Database query
$this->EE->db->select('cat_id');
$this->EE->db->where('cat_url_title', $cat_url_title);
$this->EE->db->where('group_id', $group_id);
$query = $this->EE->db->get('exp_categories');
foreach ($query->result() as $row)
{
$cat_id = $row->cat_id;
}
$query->free_result();
$this->EE->db->select('cat_name');
$this->EE->db->where('parent_id', $cat_id);
$query = $this->EE->db->get('exp_categories');
$count = $this->return_data = $query->num_rows();
$this->return_data = $count;
}
function usage()
{
ob_start();
?>
Description:
Returns the number of child categories for a category.
------------------------------------------------------
Example:
{exp:childcatcount group_id="1" cat_url_title="{segment_2}"}
Returns
3
------------------------------------------------------
Parameters:
cat_url_title="{segment_2}"
The url title for the category you want to check for child categories. REQUIRED
group_id = "1"
The category group for the category you want to check. REQUIRED
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
// END
}
/* End of file pi.childcatcount.php */
/* Location: ./system/expressionengine/third_party/plugin_name/pi.childcatcount.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment