// Purpose: Find category id. Use found category id as parameter of other tags.
<?php
/*
=====================================================
This ExpressionEngine plugin was created by Laisvunas Sopauskas
- laisvunas@classicsunlocked.net
- http://www.classicsunlocked.net/
=====================================================
This program is freeware;
you may use this code for any purpose, commercial or
private, without any further permission from the author.
=====================================================
File: pi.child_categories.php
-----------------------------------------------------
Purpose: Find all child categories after specifying parent or
sibling category. Display lists of entries posted to child
categories.
=====================================================
*/
$plugin_info = array(
'pi_name' => 'Child Categories',
'pi_version' => '1.4.1',
'pi_author' => 'Laisvunas Sopauskas',
'pi_author_url' => 'http://www.classicsunlocked.net/',
'pi_description' => 'Allows you to find all child categories after specifying parent or
sibling category and display lists of entries posted to child categories.',
'pi_usage' => child_categories::usage()
);
class Child_categories {
var $return_data = '';
function Child_categories()
{
global $TMPL, $DB;
// Fetch the tagdata
$tagdata = $TMPL->tagdata;
// Define variables
$siteclause = '';
$weblogclause = '';
$sortorderclause_categories = '';
$sortorderclause_entries = '';
$limitclause = '';
$parent_cat_name = '';
$parent_cat_url_title = '';
$child_category_id = '';
$entries_total = '';
$child_category_name = '';
$child_category_url_title = '';
$child_category_order_num = '';
$weblog_name = '';
$weblog_url = '';
$title = '';
$url_title = '';
$entry_date = '';
$tagdatanew = '';
$parentdatanew = '';
$childdatanew = '';
$entriesdatanew = '';
$parentdataexists = '';
$childdataexists = '';
$entriesdataexists = '';
$entrieswrappertop_dataexists = '';
$entrieswrapperbottom_dataexists = '';
$entrieswrappertop_data = '';
$entrieswrapperbottom_data = '';
$found_invalid = FALSE;
$parentarray = array();
// Fetch params
$parent = $TMPL->fetch_param('parent');
$sibling = $TMPL->fetch_param('sibling');
$site = $TMPL->fetch_param('site');
$child_categories_sort_by = $TMPL->fetch_param('child_categories_sort_by');
$child_categories_sort_direction = $TMPL->fetch_param('child_categories_sort_direction');
$show_empty = $TMPL->fetch_param('show_empty');
$entries_sort_by = $TMPL->fetch_param('entries_sort_by');
$entries_sort_direction = $TMPL->fetch_param('entries_sort_direction');
$entries_limit = $TMPL->fetch_param('entries_limit');
$date_format = $TMPL->fetch_param('date_format');
$weblog = $TMPL->fetch_param('weblog');
$invalid_input = $TMPL->fetch_param('invalid_input');
// At least one out of "parent" and "sibling" parameters must be defined
if ($parent === FALSE AND $sibling === FALSE)
{
if ($invalid_input === 'alert')
{
exit('Error! At least one out of "parent" and "sibling" parameters of exp:child_categories tag must be defined.');
}
$found_invalid = TRUE;
}
// Parameter "child_categories_sort_by" accepts only "name", "id" or "custom" as its value
if ($child_categories_sort_by !== FALSE AND $child_categories_sort_by !== 'name' AND $child_categories_sort_by !== 'id' AND $child_categories_sort_by !== 'custom')
{
if ($invalid_input === 'alert')
{
exit('Error! Parameter "child_categories_sort_by" of exp:child_categories tag accepts only "name", "id" or "custom" as its value.');
}
$found_invalid = TRUE;
}
// Parameter "child_categories_sort_direction" accepts only "asc" or "desc" as its value
if ($child_categories_sort_direction !== FALSE AND $child_categories_sort_direction !== 'asc' AND $child_categories_sort_direction !== 'desc')
{
if ($invalid_input === 'alert')
{
exit('Error! Parameter "child_categories_sort_direction" of exp:child_categories tag accepts only "asc" or "desc" as its value.');
}
$found_invalid = TRUE;
}
// Parameter "show_empty" accepts only "yes" or "no" as its value
if ($show_empty !== FALSE AND $show_empty !== 'yes' AND $show_empty !== 'no')
{
if ($invalid_input === 'alert')
{
exit('Error! Parameter "show_empty" of exp:child_categories tag accepts only "yes" or "no" as its value.');
}
$found_invalid = TRUE;
}
// Parameter "entries_sort_by" accepts only "date" or "title" as its value
if ($entries_sort_by !== FALSE AND $entries_sort_by !== 'date' AND $entries_sort_by !== 'title')
{
if ($invalid_input === 'alert')
{
exit('Error! Parameter "entries_sort_by" of exp:child_categories tag accepts only "date" or "title" as its value.');
}
$found_invalid = TRUE;
}
// Parameter "entries_sort_direction" accepts only "asc" or "desc" as its value
if ($entries_sort_direction !== FALSE AND $entries_sort_direction !== 'asc' AND $entries_sort_direction !== 'desc')
{
if ($invalid_input === 'alert')
{
exit('Error! Parameter "entries_sort_direction" of exp:child_categories tag accepts only "asc" or "desc" as its value.');
}
$found_invalid = TRUE;
}
if ($found_invalid === FALSE)
{
// Form weblog clause
if($weblog !== FALSE)
{
// Clean whitespace from "weblog" parameter value
$weblog = str_replace(' ', '', $weblog);
// Check if "weblog" param contains "not"
if (strpos($weblog, 'not')===0)
{
// In case "weblog" param contains "not" form SQL clause using "AND" and "!=" operators
$weblog = substr($weblog, 3);
$weblog_shortnames_array = explode('|', $weblog);
foreach($weblog_shortnames_array as $shortname)
{
$weblogclause .= " AND exp_weblogs.blog_name!='".$shortname."' ";
}
}
else
{
// In case "weblog" param does not contain "not" form SQL clause using "OR" and "=" operators
$weblog_shortnames_array = explode('|', $weblog);
if (count($weblog_shortnames_array)==1)
{
$weblogclause = " AND exp_weblogs.blog_name='".$weblog_shortnames_array[0]."' ";
}
else
{
foreach($weblog_shortnames_array as $shortname)
{
$weblogclause .= " OR exp_weblogs.blog_name='".$shortname."' ";
}
$weblogclause = substr($weblogclause, 4);
$weblogclause = " AND (".$weblogclause.")";
}
}
}
//echo $weblogclause.'<br>';
// Form site clause
if ($site !== FALSE)
{
$siteclause = " AND exp_categories.site_id='".$site."' ";
//echo $siteclause.'<br>';
}
// Form child categories sort order clause
if ($child_categories_sort_by === FALSE OR $child_categories_sort_by === 'name')
{
$sortorderclause_categories = ' ORDER BY cat_name ';
}
elseif ($child_categories_sort_by === 'id')
{
$sortorderclause_categories = ' ORDER BY cat_id ';
}
elseif ($child_categories_sort_by === 'custom')
{
$sortorderclause_categories = ' ORDER BY cat_order ';
}
if ($child_categories_sort_direction === FALSE OR $child_categories_sort_direction === 'asc')
{
$sortorderclause_categories .= ' ASC ';
}
elseif ($child_categories_sort_direction === 'desc')
{
$sortorderclause_categories .= ' DESC ';
}
//echo $sortorderclause_categories.'<br>';
// Supply default value for child categories show_empty parameter
if ($show_empty === FALSE)
{
$show_empty ='no';
}
// Form entries sort order clause
if ($entries_sort_by === FALSE OR $entries_sort_by === 'date')
{
$sortorderclause_entries = ' ORDER BY exp_weblog_titles.entry_date ';
}
elseif ($entries_sort_by === 'title')
{
$sortorderclause_entries = ' ORDER BY exp_weblog_titles.title ';
}
if ($entries_sort_direction === FALSE OR $entries_sort_direction === 'desc')
{
$sortorderclause_entries .= ' DESC ';
}
elseif ($entries_sort_direction === 'asc')
{
$sortorderclause_entries .= ' ASC ';
}
//echo $sortorderclause_entries.'<br>';
// Form entries limit clause
if ($entries_limit === FALSE)
{
$limitclause = ' LIMIT 0, 10';
}
elseif ($entries_limit === 'none')
{
$limitclause = '';
}
else
{
$limitclause = ' LIMIT 0, '.$entries_limit;
}
//echo $limitclause.'<br>';
// Form default date format string
if ($date_format === FALSE)
{
$date_format = 'Y-m-d';
}
// I. Finding data enclosed between {parent_category_start} and {parent_category_end},
// {child_category_start} and {child_category_end},
// {entries_start} and {entries_end},
// {entries_wrapper_top_start} and {entries_wrapper_top_end},
// {entries_wrapper_bottom_start} and {entries_wrapper_bottom_end} tag pairs
// Find if there are tags {parent_category_start} and {parent_category_end}
$closingtagpos = strpos($tagdata, '{parent_category_end}');
//echo $closingtagpos.'<br>';
$openingtagpos = strpos($tagdata, '{parent_category_start}');
//echo $openingtagpos.'<br>';
// In case there are tags {parent_category_start} and {parent_category_end}
// find data enclosed between them
if ($closingtagpos !== FALSE AND $openingtagpos !== FALSE)
{
$parentdataexists = TRUE;
$parentdata = substr($tagdata, 0, $closingtagpos);
$openingtagpos += 23;
$parentdata = substr($parentdata, $openingtagpos);
//echo $parentdata.'<br>';
}
// Find if there are tags {child_category_start} and {child_category_end}
$closingtagpos = strpos($tagdata, '{child_category_end}');
//echo $closingtagpos.'<br>';
$openingtagpos = strpos($tagdata, '{child_category_start}');
//echo $openingtagpos.'<br>';
// In case there are tags {child_category_start} and {child_category_end}
// find data enclosed between them
if ($closingtagpos !== FALSE AND $openingtagpos !== FALSE)
{
$childdataexists = TRUE;
$childdata = substr($tagdata, 0, $closingtagpos);
$openingtagpos += 22;
$childdata = substr($childdata, $openingtagpos);
//echo $childdata.'<br>';
}
// Find if there are tags {entries_start} and {entries_end}
$closingtagpos = strpos($tagdata, '{entries_end}');
//echo $closingtagpos.'<br>';
$openingtagpos = strpos($tagdata, '{entries_start}');
//echo $openingtagpos.'<br>';
// In case there are tags {entries_start} and {entries_end}
// find data enclosed between them
if ($closingtagpos !== FALSE AND $openingtagpos !== FALSE)
{
$entriesdataexists = TRUE;
$entriesdata = substr($tagdata, 0, $closingtagpos);
$openingtagpos += 15;
$entriesdata = substr($entriesdata, $openingtagpos);
//echo $entriesdata.'<br>';
}
// Find if there are tags {entries_wrapper_top_start} and {entries_wrapper_top_end}
$closingtagpos = strpos($tagdata, '{entries_wrapper_top_end}');
//echo $closingtagpos.'<br>';
$openingtagpos = strpos($tagdata, '{entries_wrapper_top_start}');
//echo $openingtagpos.'<br>';
// In case there are tags {entries_wrapper_top_start} and {entries_wrapper_top_end}
// find data enclosed between them
if ($closingtagpos !== FALSE AND $openingtagpos !== FALSE)
{
$entrieswrappertop_dataexists = TRUE;
$entrieswrappertop_data = substr($tagdata, 0, $closingtagpos);
//echo $entrieswrappertop_data.'<br>';
$openingtagpos += 27;
$entrieswrappertop_data = substr($entrieswrappertop_data, $openingtagpos);
//echo $entrieswrappertop_data.'<br>';
}
// Find if there are tags {entries_wrapper_bottom_start} and {entries_wrapper_top_end}
$closingtagpos = strpos($tagdata, '{entries_wrapper_bottom_end}');
//echo $closingtagpos.'<br>';
$openingtagpos = strpos($tagdata, '{entries_wrapper_bottom_start}');
//echo $openingtagpos.'<br>';
// In case there are tags {entries_wrapper_bottom_start} and {entries_wrapper_bottom_end}
// find data enclosed between them
if ($closingtagpos !== FALSE AND $openingtagpos !== FALSE)
{
$entrieswrapperbottom_dataexists = TRUE;
$entrieswrapperbottom_data = substr($tagdata, 0, $closingtagpos);
//echo $entrieswrapperbottom_data.'<br>';
$openingtagpos += 30;
$entrieswrapperbottom_data = substr($entrieswrapperbottom_data, $openingtagpos);
//echo $entrieswrapperbottom_data.'<br>';
}
// II. Dealing with parent category
// In case "sibling" parameter is defined find parent category id
if ($sibling !== FALSE)
{
// Create SQL query string to find parent category id
$todoinit = "SELECT parent_id FROM exp_categories WHERE exp_categories.cat_id='".$sibling."' ".$siteclause." LIMIT 0, 1";
//echo $todoinit.'<br>';
// Perform SQL query
$queryinit = $DB->query($todoinit);
//echo $queryinit->num_rows.'<br>';
// Find parent category id
if ($queryinit->num_rows === 1)
{
$parent = $queryinit->row['parent_id'];
//echo $parent.'<br>';
// Place parent category id into ids array
$parentarray[0] = $parent;
//echo $parentarray[0].'<br>';
}
}
// In case "sibling" parameter is not defined check if "parent" parameter provides
// one or more parent category ids
if ($sibling === FALSE)
{
// Clean whitespace from "parent" parameter value
$parent = str_replace(' ', '', $parent);
// Split value of "parent" parameter using "|" symbol as separator
$parentarray = explode('|', $parent);
//echo $parentarray[0].'<br>';
//echo $parentarray[1].'<br>';
}
if (count($parentarray) > 0)
{
foreach($parentarray as $member)
{
$parent = $member;
// Create SQL query string to find parent category name, parent category url_title, parent category description, parent category image
$todoinit2 = "SELECT cat_name, cat_url_title, cat_description, cat_image FROM exp_categories WHERE exp_categories.cat_id='".$parent."' ".$siteclause." LIMIT 0, 1";
//echo $todoinit2.'<br>';
// Perform SQL query
$queryinit2 = $DB->query($todoinit2);
//echo $queryinit2->num_rows.'<br>';
// Find parent category name, parent category url_title, parent category description, parent category image
if ($queryinit2->num_rows === 1)
{
$parent_cat_name = $queryinit2->row['cat_name'];
$parent_cat_url_title = $queryinit2->row['cat_url_title'];
$parent_cat_description = $queryinit2->row['cat_description'];
$parent_cat_image = $queryinit2->row['cat_image'];
//echo $parent_cat_name.' '.$parent_cat_url_title.' '..'<br>';
}
// If there are {parent_category_start}, {parent_category_end} tags, then
// manipulate data enclosed between them
if ($parentdataexists === TRUE)
{
$parentdatanew = $parentdata;
$parentdatanew = str_replace('{parent_category_id}', $parent, $parentdatanew);
$parentdatanew = str_replace('{parent_category_name}', $parent_cat_name, $parentdatanew);
$parentdatanew = str_replace('{parent_category_url_title}', $parent_cat_url_title, $parentdatanew);
$parentdatanew = str_replace('{parent_category_description}', $parent_cat_description, $parentdatanew);
$parentdatanew = str_replace('{parent_category_image}', $parent_cat_image, $parentdatanew);
//echo $parentdatanew.'<br>';
$tagdatanew .= $parentdatanew;
}
// III. Dealing with child categories
// Create SQL query string to find child categories ids, names, url_titles, descriptions, images
$todo = "SELECT cat_id, cat_name, cat_url_title, cat_description, cat_image, cat_order FROM exp_categories WHERE exp_categories.parent_id='".$parent."' ".$siteclause.$sortorderclause_categories;
//echo $todo.'<br>';
// Perform SQL query
$query = $DB->query($todo);
foreach ($query->result as $onerow)
{
// Find child category id, name, url_title
$child_category_id = $onerow['cat_id'];
$child_category_name = $onerow['cat_name'];
$child_category_url_title = $onerow['cat_url_title'];
$child_category_description = $onerow['cat_description'];
$child_category_image = $onerow['cat_image'];
$child_category_order_num = $onerow['cat_order'];
//echo $child_category_order_num.' '.$child_category_id.' '.$child_category_name.' '.$child_category_url_title.'<br>';
// Create SQL query string to find total number of entries posted into child category
$todonext = "SELECT exp_weblog_titles.url_title, exp_weblog_titles.title, exp_weblog_titles.entry_date, exp_weblog_titles.site_id, exp_weblogs.blog_name, exp_weblogs.blog_title, exp_weblogs.blog_url, exp_categories.cat_name, exp_categories.cat_id, exp_categories.cat_url_title FROM exp_category_posts, exp_weblog_titles, exp_weblogs, exp_categories WHERE exp_category_posts.entry_id=exp_weblog_titles.entry_id AND exp_weblog_titles.weblog_id=exp_weblogs.weblog_id AND exp_category_posts.cat_id=exp_categories.cat_id AND exp_weblog_titles.site_id=exp_categories.site_id AND exp_category_posts.cat_id='".$child_category_id."' ".$weblogclause.$siteclause.$sortorderclause_entries;
//echo $todonext.'<br>';
// Perform SQL queries
$querynext = $DB->query($todonext);
// Find total number of entries posted into child category
$entries_total = $querynext->num_rows;
//echo $entries_total.'<br>';
// In case "show_empty" parameter has the value "no" and total number of entries posted into child category is 0 do not display such category
if ($entries_total > 0 OR $show_empty === 'yes')
{
// If there are tags {child_category_start} and {child_category_end}
// manipulate data enclosed between them
if ($childdataexists === TRUE)
{
$childdatanew = $childdata;
$childdatanew = str_replace('{parent_category_id}', $parent, $childdatanew);
$childdatanew = str_replace('{parent_category_name}', $parent_cat_name, $childdatanew);
$childdatanew = str_replace('{parent_category_description}', $parent_cat_description, $childdatanew);
$childdatanew = str_replace('{parent_category_image}', $parent_cat_image, $childdatanew);
$childdatanew = str_replace('{parent_category_url_title}', $parent_cat_url_title, $childdatanew);
$childdatanew = str_replace('{child_category_id}', $child_category_id, $childdatanew);
$childdatanew = str_replace('{child_category_name}', $child_category_name, $childdatanew);
$childdatanew = str_replace('{child_category_url_title}', $child_category_url_title, $childdatanew);
$childdatanew = str_replace('{child_category_description}', $child_category_description, $childdatanew);
$childdatanew = str_replace('{child_category_image}', $child_category_image, $childdatanew);
$childdatanew = str_replace('{child_category_order_num}', $child_category_order_num, $childdatanew);
$childdatanew = str_replace('{entries_total}', $entries_total, $childdatanew);
$tagdatanew .= $childdatanew;
if ($entriesdataexists === TRUE AND $entries_total > 0 AND $entrieswrappertop_dataexists === TRUE AND $entrieswrapperbottom_dataexists === TRUE)
{
$tagdatanew .= $entrieswrappertop_data;
}
}
// IV. Dealing with titles posted into child categories
// Create SQL query string to find weblog_name, weblog_url, titles,
// url_titles and dates of entries posted into child category
$todolast = $todonext.$limitclause;
//echo $todolast.'<br>';
// Perform SQL query
$querylast = $DB->query($todolast);
// Reset incrementer
$incrementer = 1;
// If there are tagpair {entries_start}{entries_end}, then,
// first, for every title posted into child category find its
// weblog name
// weblog url
// title
// url title
// entry date
// manipulate data enclosed between them
// second, manipulate data enclosed between that tagpair
if ($entriesdataexists === TRUE)
{
foreach ($querylast->result as $rowlast)
{
$weblog_short_name = $rowlast['blog_name'];
$weblog_name = $rowlast['blog_title'];
$weblog_url = $rowlast['blog_url'];
$title = $rowlast['title'];
$url_title = $rowlast['url_title'];
$entry_date = date($date_format, $rowlast['entry_date']);
//echo $weblog_name.' '.$weblog_url.' '.$title.' '.$url_title.' '.$entry_date.'<br>';
$entriesdatanew = $entriesdata;
$entriesdatanew = str_replace('{parent_category_id}', $parent, $entriesdatanew);
$entriesdatanew = str_replace('{parent_category_name}', $parent_cat_name, $entriesdatanew);
$entriesdatanew = str_replace('{parent_category_description}', $parent_cat_description, $entriesdatanew);
$entriesdatanew = str_replace('{parent_category_image}', $parent_cat_image, $entriesdatanew);
$entriesdatanew = str_replace('{parent_category_url_title}', $parent_cat_url_title, $entriesdatanew);
$entriesdatanew = str_replace('{child_category_id}', $child_category_id, $entriesdatanew);
$entriesdatanew = str_replace('{child_category_name}', $child_category_name, $entriesdatanew);
$entriesdatanew = str_replace('{child_category_url_title}', $child_category_url_title, $entriesdatanew);
$entriesdatanew = str_replace('{child_category_description}', $child_category_description, $entriesdatanew);
$entriesdatanew = str_replace('{child_category_image}', $child_category_image, $entriesdatanew);
$entriesdatanew = str_replace('{child_category_order_num}', $child_category_order_num, $entriesdatanew);
$entriesdatanew = str_replace('{entries_total}', $entries_total, $entriesdatanew);
$entriesdatanew = str_replace('{weblog_short_name}', $weblog_short_name, $entriesdatanew);
$entriesdatanew = str_replace('{weblog_name}', $weblog_name, $entriesdatanew);
$entriesdatanew = str_replace('{weblog_url}', $weblog_url, $entriesdatanew);
$entriesdatanew = str_replace('{title}', $title, $entriesdatanew);
$entriesdatanew = str_replace('{url_title}', $url_title, $entriesdatanew);
$entriesdatanew = str_replace('{entry_date}', $entry_date, $entriesdatanew);
$entriesdatanew = str_replace('{count}', $incrementer, $entriesdatanew);
$tagdatanew .= $entriesdatanew;
if (($incrementer === $entries_total OR $incrementer == $entries_limit) AND $entrieswrappertop_dataexists === TRUE AND $entrieswrapperbottom_dataexists === TRUE)
{
$tagdatanew .= $entrieswrapperbottom_data;
}
//$tagdatanew .= '<br> incrementer: '.$incrementer.' entries_total: '.$entries_total.' entries_limit: '.$entries_limit.' entrieswrapperbottom_data: '.$entrieswrapperbottom_data.'<br>';
$incrementer++;
}
}
}
}
//echo $tagdatanew.'<br>';
// Output transformed tagdata
$this->return_data = $tagdatanew;
}
}
}
}
// END FUNCTION
// ----------------------------------------
// Plugin Usage
// ----------------------------------------
// This function describes how the plugin is used.
// Make sure and use output buffering
function usage()
{
ob_start();
?>
PARAMETERS:
1) parent - Optional. Allows you to specify parent category id number
(the id number of each category is displayed in the Control Panel).
You can stack parent categories using pipe character e.g. parent="3|16|28".
2) sibling - Optional. Allows you to specify child category id number
(the id number of each category is displayed in the Control Panel).
Either "parent" or "sibling" parameter MUST BE defined.
3) site - Optional. Allows you to specify site id number.
4) child_categories_sort_by - Optional. Allows you to specify sort order
of child categories. This parameter accepts three values: "name" (child
categories will be sorted by name), "id" (child categories will be sorted
by id number), and "custom" (child categories will be sorted using custom order
as defined in control panel). Default value is "name".
5) child_categories_sort_direction - Optional. Allows you to specify sort direction
of child categories. This parameter accepts two values: "asc" and "desc".
Default value is "asc".
6) show_empty - Optional. Allows you to specify if child categories having no
entries should be displayed or not. This parameter accepts two values: "yes" and "no".
Default value is "no".
7) entries_sort_by - Optional. Allows you to specify sort order of entries.
This parameter accepts two values: "title" and "date". Default value is "date".
8) entries_sort_direction - Optional. Allows you to specify sort direction
of entries. This parameter accepts two values: "asc" and "desc".
Default value is "desc".
9) entries_limit - Optional. Allows you to specify how many entries posted into
child category should be displayed. This parameter accepts as its value an integer
or "none". Default value is "10". Value "none" means that all entries will be
displayed.
10) date_format - Optional. Allows you to specify PHP date format string
(Not ExpressionEngine's date format string!). Default value is "Y-m-d".
11) invalid_input - Optional. Accepts two values: “alert†and “silenceâ€.
Default value is “silenceâ€. If the value is “alertâ€, then in cases when some
parameter’s value is invalid plugin exits and PHP alert is being shown;
if the value is “silenceâ€, then in cases when some parameter’s value
is invalid plugin finishes its work without any alert being shown.
Set this parameter to “alert†for development, and to “silence†- for deployment.
VARIABLE PAIRS:
1) {parent_category_start}{parent_category_end} - Allows you to specify portion of
code which will be iterated as many times as there are parent categories.
Single variables available for use inside this variable pair:
{parent_category_id}
{parent_category_name}
{parent_category_url_title}
{parent_category_description}
{parent_category_image}
2) {child_category_start}{child_category_end} - Allows you to specify portion of
code which will be iterated as many times as there are child categories.
Single variables available for use inside this variable pair:
{parent_category_id}
{parent_category_name}
{parent_category_url_title}
{parent_category_description}
{parent_category_image}
{child_category_id}
{child_category_name}
{child_category_url_title}
{child_category_description}
{child_category_image}
{child_category_order_num}
{entries_total}
3) {entries_start}{entries_end} - Allows you to specify portion of
code which will be iterated as many times as there are entries posted into child
category. Single variables available for use inside this variable pair:
{parent_category_id}
{parent_category_name}
{parent_category_url_title}
{parent_category_description}
{parent_category_image}
{child_category_id}
{child_category_name}
{child_category_url_title}
{child_category_description}
{child_category_image}
{child_category_order_num}
{entries_total}
{weblog_name}
{weblog_short_name}
{weblog_url}
{title}
{url_title}
{entry_date}
{count}
4) {entries_wrapper_top_start}{entries_wrapper_top_end} - Allows you to specify top part of
the code with which you want to wrap output of {entries_start}{entries_end} variable pair.
5) {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} - Allows you to specify bottom part of
the code with which you want to wrap output of {entries_start}{entries_end} variable pair.
The tag {exp:child_categories} MUST contain at least one variable pair out of
{parent_category_start}{parent_category_end}, {child_category_start}{child_category_end} and
{entries_start}{entries_end} variable pairs and each single variable MUST BE inside
relevant variable pair.
SINGLE VARIABLES:
1) {parent_category_id} - outputs id number of parent category.
2) {parent_category_name} - outputs name of parent category.
3) {parent_category_url_title} - outputs url title of parent category.
4) {parent_category_description} - outputs description title of parent category.
5) {parent_category_image} - outputs url of the image of parent category.
6) {child_category_id} - outputs id number of child category.
7) {child_category_name} - outputs name of child category.
8) {child_category_url_title} - outputs url title of child category.
9) {child_category_description} - outputs description title of child category.
10) {child_category_image} - outputs url of the image of child category.
11) {child_category_order_num} - outputs number used for custom ordering of
categories.
12) {entries_total} - outputs total number of entries posted into child category.
13) {weblog_name} - outputs full weblog name into which entry is posted.
14) {weblog_short_name} - outputs short weblog name into which entry is posted.
15) {weblog_url} - outputs weblog url as specified in control panel.
16) {title} - outputs title of entry.
17) {url_title} - outputs url title of entry.
18) {entry_date} - outputs entry date of entry.
19) {count} - outputs order number of entry.
EXAMPLE OF USAGE:
{exp:child_categories parent="18|29" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="3" site="1"}
{parent_category_start}
<h1><a href="{homepage}/category/{parent_category_url_title}/">{parent_category_name}</a></h1>
{parent_category_end}
{child_category_start}
<h2><a href="{homepage}/category/{child_category_url_title}/">{child_category_name}</a></h2>
Total entries: {entries_total}<br>
{child_category_end}
{entries_wrapper_top_start}< div style="border: 1px solid red;" >{entries_wrapper_top_end}
{entries_start}
<a href="{weblog_url}{url_title}">{title}</a> Weblog: {weblog_name}, posted: {entry_date}<br>
{entries_end}
{entries_wrapper_bottom_start}< /div >{entries_wrapper_bottom_end}
{/exp:child_categories}
This code will output:
Parent category 18
Child category
Total entries
Entry
Entry
Entry
Child category
Total entries
Entry
Entry
Entry
Child category
Total entries
Entry
Entry
Entry
Parent category 29
Child category
Total entries
Entry
Entry
Entry
Child category
Total entries
Entry
Entry
Entry
Place the tag {exp:child_categories} in any of your templates.
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
// END USAGE
}
// END CLASS
?>