-
-
Save nathanpitman/8446686 to your computer and use it in GitHub Desktop.
Modified to use category IDs instead of category URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
$plugin_info = array( | |
'pi_name' => 'Child Category Count', | |
'pi_version' =>'1.0', | |
'pi_author' =>'Nathan Pitman', | |
'pi_author_url' => 'http://ninefour.co.uk/labs', | |
'pi_description' => 'Returns number of child categories given a parent category ID', | |
'pi_usage' => Childcatcount::usage() | |
); | |
class Childcatcount { | |
var $return_data = ''; | |
function Childcatcount() | |
{ | |
$this->EE =& get_instance(); | |
//Get parameters | |
$cat_id = $this->EE->TMPL->fetch_param('cat_id'); | |
$count = 0; | |
//Database query | |
$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 cat_id="{segment_2}"} | |
Returns | |
3 | |
------------------------------------------------------ | |
Parameters: | |
cat_id="{segment_2}" | |
The id for the category you want to check for child categories. REQUIRED | |
<?php | |
$buffer = ob_get_contents(); | |
ob_end_clean(); | |
return $buffer; | |
} | |
// END | |
} | |
/* End of file pi.childcatcount.php */ | |
/* Location: ./system/expressionengine/third_party/childcatcount/pi.childcatcount.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment