Untitled diff

Created Diff never expires
4 removals
496 lines
16 additions
508 lines
<?php
<?php
/*
/*
Plugin Name: Hierarchical Pages
Plugin Name: Hierarchical Pages
Version: 1.4
Version: 1.4
Plugin URI: http://www.saltriversystems.com/website/hierpage/
Plugin URI: http://www.saltriversystems.com/website/hierpage/
Description: Adds sidebar widgets to display a context-based list of "nearby" pages, and to display nested categories.
Description: Adds sidebar widgets to display a context-based list of "nearby" pages, and to display nested categories.
Author: William Lindley
Author: William Lindley
Author URI: http://www.wlindley.com/
Author URI: http://www.wlindley.com/
License: GPL2
License: GPL2
*/
*/
/* Copyright 2007-2012 William Lindley (email : wlindley -at- wlindley -dot- com)
/* Copyright 2007-2012 William Lindley (email : wlindley -at- wlindley -dot- com)
This program is free software; you can redistribute it and/or modify
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
if (!class_exists('SRCS_WP_Widget')) {
if (!class_exists('SRCS_WP_Widget')) {
class SRCS_WP_Widget extends WP_Widget
class SRCS_WP_Widget extends WP_Widget
{
{
function form_html($instance) {
function form_html($instance) {
$option_menu = $this->known_params(1);
$option_menu = $this->known_params(1);
foreach (array_keys($option_menu) as $param) {
foreach (array_keys($option_menu) as $param) {
$param_display[$param] = htmlspecialchars($instance[$param]);
$param_display[$param] = htmlspecialchars($instance[$param]);
}
}
foreach ($option_menu as $option_name => $option) {
foreach ($option_menu as $option_name => $option) {
$checkval='';
$checkval='';
$desc = '';
$desc = '';
if ($option['desc'])
if ($option['desc'])
$desc = "<br /><small>{$option['desc']}</small>";
$desc = "<br /><small>{$option['desc']}</small>";
switch ($option['type']) {
switch ($option['type']) {
case 'checkbox':
case 'checkbox':
if ($instance[$option_name]) // special HTML and override value
if ($instance[$option_name]) // special HTML and override value
$checkval = 'checked="yes" ';
$checkval = 'checked="yes" ';
$param_display[$option_name] = 'yes';
$param_display[$option_name] = 'yes';
break;
break;
case '':
case '':
$option['type'] = 'text';
$option['type'] = 'text';
break;
break;
}
}
print '<p style="text-align:right;"><label for="' . $this->get_field_name($option_name) . '">' .
print '<p style="text-align:right;"><label for="' . $this->get_field_name($option_name) . '">' .
__($option['title']) .
__($option['title']) .
' <input style="width: 200px;" id="' . $this->get_field_id($option_name) .
' <input style="width: 200px;" id="' . $this->get_field_id($option_name) .
'" name="' . $this->get_field_name($option_name) .
'" name="' . $this->get_field_name($option_name) .
"\" type=\"{$option['type']}\" {$checkval}value=\"{$param_display[$option_name]}\" /></label>$desc</p>";
"\" type=\"{$option['type']}\" {$checkval}value=\"{$param_display[$option_name]}\" /></label>$desc</p>";
}
}
}
}
}
}
}
}
class HierPageWidget extends SRCS_WP_Widget
class HierPageWidget extends SRCS_WP_Widget
{
{
/**
/**
* Declares the HierPageWidget class.
* Declares the HierPageWidget class.
*
*
*/
*/
function HierPageWidget(){
function HierPageWidget(){
$widget_ops = array('classname' => 'widget_hier_page', 'description' => __( "Hierarchical Page Directory Widget") );
$widget_ops = array('classname' => 'widget_hier_page', 'description' => __( "Hierarchical Page Directory Widget") );
$control_ops = array('width' => 300, 'height' => 300);
$control_ops = array('width' => 300, 'height' => 300);
$this->WP_Widget('hierpage', __('Hierarchical Pages'), $widget_ops, $control_ops);
$this->WP_Widget('hierpage', __('Hierarchical Pages'), $widget_ops, $control_ops);
}
}
/**
/**
* Helper function
* Helper function
*
*
*/
*/
function hierpages_list_pages($args = '') {
function hierpages_list_pages($args = '') {
global $post;
global $post;
global $wp_query;
global $wp_query;
if ( !isset($args['echo']) )
if ( !isset($args['echo']) )
$args['echo'] = 1;
$args['echo'] = 1;
$output = '';
$output = '';
if(!$args['post_type'])$args['post_type'] = 'page';
// Query pages. NOTE: The array is sorted in alphabetical, or menu, order.
// Query pages. NOTE: The array is sorted in alphabetical, or menu, order.
$pages = & get_pages($args);
$pages = & get_pages($args);
$page_info = Array();
$page_info = Array();
if ( $pages ) {
if ( $pages ) {
$current_post = $wp_query->get_queried_object_id();
$current_post = $wp_query->get_queried_object_id();
foreach ( $pages as $page ) {
foreach ( $pages as $page ) {
$page_info[$page->ID]['parent'] = $page->post_parent;
$page_info[$page->ID]['parent'] = $page->post_parent;
$page_info[$page->post_parent]['children'][] = $page->ID;
$page_info[$page->post_parent]['children'][] = $page->ID;
}
}
// Display the front page?
// Display the front page?
$front_page = -1; // assume no static front page
$front_page = -1; // assume no static front page
if ('page' == get_option('show_on_front')) {
if ('page' == get_option('show_on_front')) {
$front_page = get_option('page_on_front');
$front_page = get_option('page_on_front');
// Regard flag: always show front page? Otherwise: Show front page only if it has children
// Regard flag: always show front page? Otherwise: Show front page only if it has children
if (($args['show_home'] == 'yes') || (sizeof($page_info[$front_page]['children']))) {
if (($args['show_home'] == 'yes') || (sizeof($page_info[$front_page]['children']))) {
$page_info[$front_page]['show'] = 1; // always show front page
$page_info[$front_page]['show'] = 1; // always show front page
}
}
}
}
// add all children of the root node, but only to single depth.
// add all children of the root node, but only to single depth.
if ($args['show_root'] == 'yes') {
if ($args['show_root'] == 'yes') {
foreach ( $page_info[0]['children'] as $child ) {
foreach ( $page_info[0]['children'] as $child ) {
if ($child != $front_page) {
if ($child != $front_page) {
$page_info[$child]['show'] = 1;
$page_info[$child]['show'] = 1;
}
}
}
}
}
}
if (is_page()) {
if (is_post_type_hierarchical($args['post_type'])) {
if ($post->ID != $front_page ) {
if ($post->ID != $front_page ) {
// The current page is always shown, unless it is the static front page (see above)
// The current page is always shown, unless it is the static front page (see above)
$page_info[$post->ID]['show'] = 1;
$page_info[$post->ID]['show'] = 1;
}
}
// show the current page's children, if any.
// show the current page's children, if any.
if (is_array($page_info[$current_post]['children'] )) {
if (is_array($page_info[$current_post]['children'] )) {
foreach ( $page_info[$current_post]['children'] as $child ) {
foreach ( $page_info[$current_post]['children'] as $child ) {
$page_info[$child]['show'] = 1;
$page_info[$child]['show'] = 1;
}
}
}
}
$post_parent = $page_info[$current_post]['parent'];
$post_parent = $page_info[$current_post]['parent'];
if ($post_parent && ($args['show_siblings'] == 'yes')) {
if ($post_parent && ($args['show_siblings'] == 'yes')) {
// if showing siblings, add the current page's parent's other children.
// if showing siblings, add the current page's parent's other children.
foreach ( $page_info[$post_parent]['children'] as $child ) {
foreach ( $page_info[$post_parent]['children'] as $child ) {
if ($child != $front_page) {
if ($child != $front_page) {
$page_info[$child]['show'] = 1;
$page_info[$child]['show'] = 1;
}
}
}
}
// Also show parent node's siblings.
// Also show parent node's siblings.
$post_grandparent = $page_info[$post_parent]['parent'];
$post_grandparent = $page_info[$post_parent]['parent'];
if ($post_grandparent) {
if ($post_grandparent) {
foreach ( $page_info[$post_grandparent]['children'] as $child ) {
foreach ( $page_info[$post_grandparent]['children'] as $child ) {
if ($child != $front_page) {
if ($child != $front_page) {
$page_info[$child]['show'] = 1;
$page_info[$child]['show'] = 1;
}
}
}
}
}
}
}
}
// add all ancestors of the current page.
// add all ancestors of the current page.
while ($post_parent) {
while ($post_parent) {
$page_info[$post_parent]['show'] = 1;
$page_info[$post_parent]['show'] = 1;
// show that page's children, if any.
// show that page's children, if any.
if (is_array($page_info[$post_parent]['children'] )) {
if (is_array($page_info[$post_parent]['children'] )) {
foreach ( $page_info[$post_parent]['children'] as $child ) {
foreach ( $page_info[$post_parent]['children'] as $child ) {
$page_info[$child]['show'] = 1;
$page_info[$child]['show'] = 1;
}
}
}
}
$post_parent = $page_info[$post_parent]['parent'];
$post_parent = $page_info[$post_parent]['parent'];
}
}
}
}
// Add pages that were selected
// Add pages that were selected
$my_includes = Array();
$my_includes = Array();
foreach ( $pages as $page ) {
foreach ( $pages as $page ) {
if ($page_info[$page->ID]['show']) {
if ($page_info[$page->ID]['show']) {
$my_includes[] = $page->ID;
$my_includes[] = $page->ID;
}
}
}
}
if ($args['child_of']) {
if ($args['child_of']) {
$my_includes[] = $args['child_of'];
$my_includes[] = $args['child_of'];
}
}
if (!empty($my_includes)) {
if (!empty($my_includes)) {
// List pages, if any. Blank title_li suppresses unwanted elements.
// List pages, if any. Blank title_li suppresses unwanted elements.
$output .= wp_list_pages( Array('title_li' => '',
$output .= wp_list_pages( Array('title_li' => '',
'sort_column' => $args['sort_column'],
'sort_column' => $args['sort_column'],
'sort_order' => $args['sort_order'],
'sort_order' => $args['sort_order'],
'include' => $my_includes) );
'include' => $my_includes,
'post_type'=> $args['post_type']
) );
}
}
}
}
$output = apply_filters('wp_list_pages', $output);
$output = apply_filters('wp_list_pages', $output);
if ( $args['echo'] )
if ( $args['echo'] )
echo $output;
echo $output;
else
else
return $output;
return $output;
}
}
/**
/**
* Displays the Widget
* Displays the Widget
*
*
*/
*/
function widget($args, $instance){
function widget($args, $instance){
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
$known_params = $this->known_params(0);
$known_params = $this->known_params(0);
foreach ($known_params as $param) {
foreach ($known_params as $param) {
if (strlen($instance[$param])) {
if (strlen($instance[$param])) {
$page_options[$param] = $instance[$param];
$page_options[$param] = $instance[$param];
}
}
}
}
if ($instance['menu_order'] == 'yes') { // Deprecated, eliminated upon form display (see below)
if ($instance['menu_order'] == 'yes') { // Deprecated, eliminated upon form display (see below)
$page_options['sort_column']='menu_order,post_title';
$page_options['sort_column']='menu_order,post_title';
}
}
print $args['before_widget'];
print $args['before_widget'];
if ( $title )
if ( $title )
print "{$args['before_title']}{$title}{$args['after_title']}";
print "{$args['before_title']}{$title}{$args['after_title']}";
print '<ul>';
print '<ul>';
$this->hierpages_list_pages($page_options);
$this->hierpages_list_pages($page_options);
print "</ul>{$args['after_widget']}";
print "</ul>{$args['after_widget']}";
}
}
function known_params ($options = 0) {
function known_params ($options = 0) {
$option_menu = array('title' => array('title' => 'Title:'),
$option_menu = array('title' => array('title' => 'Title:'),
'show_siblings' => array('title' => 'Show siblings to the current page?',
'show_siblings' => array('title' => 'Show siblings to the current page?',
'type' => 'checkbox'),
'type' => 'checkbox'),
'show_root' => array('title' => 'Always show top-level pages?',
'show_root' => array('title' => 'Always show top-level pages?',
'type' => 'checkbox'),
'type' => 'checkbox'),
'show_home' => array('title' => 'Show the static home page?',
'show_home' => array('title' => 'Show the static home page?',
'desc' => '(always shown if it has child pages)',
'desc' => '(always shown if it has child pages)',
'type' => 'checkbox'),
'type' => 'checkbox'),
'child_of' => array('title' => 'Root page ID:'),
'child_of' => array('title' => 'Root page ID:'),
'exclude' => array('title' => 'Exclude pages:',
'exclude' => array('title' => 'Exclude pages:',
'desc' => 'List of page IDs to exclude'),
'desc' => 'List of page IDs to exclude'),
'sort_column' => array('title' => 'Sort field:',
'sort_column' => array('title' => 'Sort field:',
'desc' => 'Comma-separated list: <em>post_title, menu_order, post_date, post_modified, ID, post_author, post_name</em>'),
'desc' => 'Comma-separated list: <em>post_title, menu_order, post_date, post_modified, ID, post_author, post_name</em>'),
'sort_order' => array('title' => 'Sort direction:',
'sort_order' => array('title' => 'Sort direction:',
'desc' => '(default: ASC)'),
'desc' => '(default: ASC)'),
'meta_key' => array('title' => 'Meta Key:'),
'meta_key' => array('title' => 'Meta Key:'),
'meta_value' => array('title' => 'Meta-key Value:',
'meta_value' => array('title' => 'Meta-key Value:',
'desc' => 'for selecting pages by custom fields'),
'desc' => 'for selecting pages by custom fields'),
'authors' => array('title' => 'Authors:'),
'authors' => array('title' => 'Authors:'),
'post_status' => array('title' => 'Post status:',
'post_status' => array('title' => 'Post status:',
'desc' => '(default: publish)'),
'desc' => '(default: publish)'),
'post_type' => array('title' => 'Post type:',
'desc' => '(default: page)'),
);
);
return ($options ? $option_menu : array_keys($option_menu));
return ($options ? $option_menu : array_keys($option_menu));
}
}
/**
/**
* Saves the widget's settings.
* Saves the widget's settings.
*
*
*/
*/
function update($new_instance, $old_instance){
function update($new_instance, $old_instance){
$instance = $old_instance;
$instance = $old_instance;
$known_params = $this->known_params();
$known_params = $this->known_params();
unset($instance['menu_order']);
unset($instance['menu_order']);
foreach ($known_params as $param) {
foreach ($known_params as $param) {
$instance[$param] = strip_tags(stripslashes($new_instance[$param]));
$instance[$param] = strip_tags(stripslashes($new_instance[$param]));
}
}
$instance['sort_order'] = strtolower($instance['sort_order']) == 'desc'?'DESC':'ASC';
$instance['sort_order'] = strtolower($instance['sort_order']) == 'desc'?'DESC':'ASC';
return $instance;
return $instance;
}
}
/**
/**
* Creates the edit form for the widget.
* Creates the edit form for the widget.
*
*
*/
*/
function form($instance){
function form($instance){
$instance = wp_parse_args( (array) $instance, array('title'=>'') );
$instance = wp_parse_args( (array) $instance, array('title'=>'') );
if ($instance['menu_order']) {
if ($instance['menu_order']) {
$instance['sort_column'] = 'menu_order,post_title';
$instance['sort_column'] = 'menu_order,post_title';
}
}
if (empty($instance['sort_column'])) {
if (empty($instance['sort_column'])) {
$instance['sort_column'] = 'post_title';
$instance['sort_column'] = 'post_title';
}
}
$this->form_html($instance);
$this->form_html($instance);
}
}
}// END class
}// END class
/**
/**
* Register Hierarchical Pages widget.
* Register Hierarchical Pages widget.
*
*
* Calls 'widgets_init' action after the widget has been registered.
* Calls 'widgets_init' action after the widget has been registered.
*/
*/
function HierPageInit() {
function HierPageInit() {
register_widget('HierPageWidget');
register_widget('HierPageWidget');
}
}
/*
/*
* Plugin Name: Hierarchical Categories (combined with Hierarchical Pages)
* Plugin Name: Hierarchical Categories (combined with Hierarchical Pages)
* Plugin URI: http://www.wlindley.com/
* Plugin URI: http://www.wlindley.com/
* Description: Adds a sidebar widget to display a context-based list of "nearby" categories.
* Description: Adds a sidebar widget to display a context-based list of "nearby" categories.
* Author: William Lindley
* Author: William Lindley
* Author URI: http://www.wlindley.com/
* Author URI: http://www.wlindley.com/
*/
*/
class HierCatWidget extends SRCS_WP_Widget
class HierCatWidget extends SRCS_WP_Widget
{
{
/**
/**
* Declares our class.
* Declares our class.
*
*
*/
*/
function HierCatWidget(){
function HierCatWidget(){
$widget_ops = array('classname' => 'widget_hier_cat', 'description' => __( "Hierarchical Category Widget") );
$widget_ops = array('classname' => 'widget_hier_cat', 'description' => __( "Hierarchical Category Widget") );
$control_ops = array('width' => 300, 'height' => 300);
$control_ops = array('width' => 300, 'height' => 300);
$this->WP_Widget('hiercat', __('Hierarchical Categories'), $widget_ops, $control_ops);
$this->WP_Widget('hiercat', __('Hierarchical Categories'), $widget_ops, $control_ops);
}
}
/**
/**
* Helper function
* Helper function
*
*
*/
*/
function hiercat_list_cats($args) {
function hiercat_list_cats($args) {
global $post;
global $post;
global $wp_query;
global $wp_query;
if ( !isset($args['echo']) )
if ( !isset($args['echo']) )
$args['echo'] = 1;
$args['echo'] = 1;
$sort_column = $args['sort_column'];
$sort_column = $args['sort_column'];
$output = '';
$output = '';
// Query categories.
// Query categories.
$cats = & get_categories($args);
$cats = & get_categories($args);
if ($cats['errors']) {
if ($cats['errors']) {
print "<pre>"; print_r($cats); print "</pre>";
print "<pre>"; print_r($cats); print "</pre>";
return;
return;
}
}
$cat_info = Array();
$cat_info = Array();
if ( $cats ) {
if ( $cats ) {
$current_cat = $wp_query->get_queried_object_id();
$current_cat = $wp_query->get_queried_object_id();
foreach ( $cats as $cat ) {
foreach ( $cats as $cat ) {
$cat_info[$cat->term_id]['parent'] = $cat->category_parent;
$cat_info[$cat->term_id]['parent'] = $cat->category_parent;
$cat_info[$cat->category_parent]['children'][] = $cat->term_id;
$cat_info[$cat->category_parent]['children'][] = $cat->term_id;
}
}
// add all children of the root node, but only to single depth.
// add all children of the root node, but only to single depth.
foreach ( $cat_info[0]['children'] as $child ) {
foreach ( $cat_info[0]['children'] as $child ) {
$cat_info[$child]['show'] = 1;
$cat_info[$child]['show'] = 1;
}
}
// If currently displaying a category, taxonomy, or tag; AND
// If currently displaying a category, taxonomy, or tag; AND
// if it is the same as the one in this widget...
// if it is the same as the one in this widget...
if ((is_category() || is_tax() || is_tag()) &&
if ((is_category() || is_tax() || is_tag()) &&
($args['taxonomy'] == get_queried_object()->taxonomy ) ) {
($args['taxonomy'] == get_queried_object()->taxonomy ) ) {
// show the current category's children, if any.
// show the current category's children, if any.
if (is_array($cat_info[$current_cat]['children'] )) {
if (is_array($cat_info[$current_cat]['children'] )) {
foreach ( $cat_info[$current_cat]['children'] as $child ) {
foreach ( $cat_info[$current_cat]['children'] as $child ) {
$cat_info[$child]['show'] = 1;
$cat_info[$child]['show'] = 1;
}
}
}
}
$cat_parent = $cat_info[$current_cat]['parent'];
$cat_parent = $cat_info[$current_cat]['parent'];
if ($cat_parent && ($args['show_siblings'] == 'yes')) {
if ($cat_parent && ($args['show_siblings'] == 'yes')) {
// if showing siblings, add the current category's parent's other children.
// if showing siblings, add the current category's parent's other children.
foreach ( $cat_info[$cat_parent]['children'] as $child ) {
foreach ( $cat_info[$cat_parent]['children'] as $child ) {
$cat_info[$child]['show'] = 1;
$cat_info[$child]['show'] = 1;
}
}
# Also show parent node's siblings.
# Also show parent node's siblings.
$cat_grandparent = $cat_info[$cat_parent]['parent'];
$cat_grandparent = $cat_info[$cat_parent]['parent'];
if ($cat_grandparent) {
if ($cat_grandparent) {
foreach ( $cat_info[$cat_grandparent]['children'] as $child ) {
foreach ( $cat_info[$cat_grandparent]['children'] as $child ) {
$cat_info[$child]['show'] = 1;
$cat_info[$child]['show'] = 1;
}
}
}
}
}
}
// add all ancestors of the current category.
// add all ancestors of the current category.
while ($cat_parent) {
while ($cat_parent) {
$cat_info[$cat_parent]['show'] = 1;
$cat_info[$cat_parent]['show'] = 1;
$cat_parent = $cat_info[$cat_parent]['parent'];
$cat_parent = $cat_info[$cat_parent]['parent'];
}
}
}
}
$my_includes = Array();
$my_includes = Array();
// Add categories that were selected
// Add categories that were selected
foreach ( $cats as $cat ) {
foreach ( $cats as $cat ) {
if ($cat_info[$cat->term_id]['show']) {
if ($cat_info[$cat->term_id]['show']) {
$my_includes[] =$cat->term_id;
$my_includes[] =$cat->term_id;
}
}
}
}
if (!empty($my_includes)) {
if (!empty($my_includes)) {
// List categories, if any. Blank title_li suppresses unwanted elements.
// List categories, if any. Blank title_li suppresses unwanted elements.
$qargs = Array('title_li' => '', 'hide_empty' => 0, 'include' => $my_includes,
$qargs = Array('title_li' => '', 'hide_empty' => 0, 'include' => $my_includes,
'order' => $args['order'], 'orderby' => $args['orderby'],
'order' => $args['order'], 'orderby' => $args['orderby'],
'show_count' => $args['show_count']);
'show_count' => $args['show_count']);
if (!empty($args['taxonomy'])) {
if (!empty($args['taxonomy'])) {
$qargs['taxonomy'] = $args['taxonomy'];
$qargs['taxonomy'] = $args['taxonomy'];
}
}
$output .= wp_list_categories( $qargs );
$output .= wp_list_categories( $qargs );
}
}
}
}
$output = apply_filters('wp_list_categories', $output);
$output = apply_filters('wp_list_categories', $output);
if ( $args['echo'] )
if ( $args['echo'] )
echo $output;
echo $output;
else
else
return $output;
return $output;
}
}
function known_params ($options = 0) {
function known_params ($options = 0) {
$option_menu = array('title' => array('title' => 'Title:'),
$option_menu = array('title' => array('title' => 'Title:'),
'show_siblings' => array('title' => 'Show siblings to the current category?',
'show_siblings' => array('title' => 'Show siblings to the current category?',
'type' => 'checkbox'),
'type' => 'checkbox'),
'include' => array('title' => 'Include:',
'include' => array('title' => 'Include:',
'desc' => 'Comma-delimited list of category IDs, or blank for all'),
'desc' => 'Comma-delimited list of category IDs, or blank for all'),
'exclude' => array('title' => 'Exclude:'),
'exclude' => array('title' => 'Exclude:'),
'orderby' => array('title' => 'Sort field:',
'orderby' => array('title' => 'Sort field:',
'desc' => 'Enter one of: <em>name, count, term_group, slug</em> or a custom value. Default: name'),
'desc' => 'Enter one of: <em>name, count, term_group, slug</em> or a custom value. Default: name'),
'order' => array('title' => 'Sort direction:',
'order' => array('title' => 'Sort direction:',
'desc' => '(default: ASC)'),
'desc' => '(default: ASC)'),
'child_of' => array('title' => 'Only display Categories below this ID'),
'child_of' => array('title' => 'Only display Categories below this ID'),
'hide_empty' => array('title' => 'Hide empty categories?',
'hide_empty' => array('title' => 'Hide empty categories?',
'type' => 'checkbox'),
'type' => 'checkbox'),
'show_count' => array('title' => 'Show count of category entries?',
'show_count' => array('title' => 'Show count of category entries?',
'type' => 'checkbox'),
'type' => 'checkbox'),
'taxonomy' => array('title' => 'Custom taxonomy:'),
'taxonomy' => array('title' => 'Custom taxonomy:'),
);
);
if ($options) {
if ($options) {
$taxons = get_taxonomies();
$taxons = get_taxonomies();
$option_menu['taxonomy']['desc'] = 'Enter one of: <em>' .
$option_menu['taxonomy']['desc'] = 'Enter one of: <em>' .
implode(', ',array_keys($taxons)) . '</em> or blank for post categories.';
implode(', ',array_keys($taxons)) . '</em> or blank for post categories.';
}
}
return ($options ? $option_menu : array_keys($option_menu));
return ($options ? $option_menu : array_keys($option_menu));
}
}
/**
/**
* Displays the Widget
* Displays the Widget
*
*
*/
*/
function widget($args, $instance){
function widget($args, $instance){
$known_params = $this->known_params(0);
$known_params = $this->known_params(0);
foreach ($known_params as $param) {
foreach ($known_params as $param) {
if (strlen($instance[$param]))
if (strlen($instance[$param]))
$cat_options[$param] = $instance[$param];
$cat_options[$param] = $instance[$param];
}
}
$cat_options['title'] = apply_filters('widget_title', $cat_options['title']);
$cat_options['title'] = apply_filters('widget_title', $cat_options['title']);
// WordPress defaults to hiding: thus, always specify.
// WordPress defaults to hiding: thus, always specify.
$cat_options['hide_empty'] = $cat_options['hide_empty'] == 'yes' ? 1 : 0;
$cat_options['hide_empty'] = $cat_options['hide_empty'] == 'yes' ? 1 : 0;
print $args['before_widget'];
print $args['before_widget'];
if ( strlen($cat_options['title']) )
if ( strlen($cat_options['title']) )
print "{$args['before_title']}{$cat_options['title']}{$args['after_title']}";
print "{$args['before_title']}{$cat_options['title']}{$args['after_title']}";
print "<ul>";
print "<ul>";
$this->hiercat_list_cats($cat_options);
$this->hiercat_list_cats($cat_options);
print "</ul>{$after_widget}";
print "</ul>{$after_widget}";
}
}
/**
/**
* Saves the widget's settings.
* Saves the widget's settings.
*
*
*/
*/
function update($new_instance, $old_instance){
function update($new_instance, $old_instance){
$instance = $old_instance;
$instance = $old_instance;
$known_params = $this->known_params();
$known_params = $this->known_params();
foreach ($known_params as $param) {
foreach ($known_params as $param) {
$instance[$param] = strip_tags(stripslashes($new_instance[$param]));
$instance[$param] = strip_tags(stripslashes($new_instance[$param]));
}
}
return $instance;
return $instance;
}
}
/**
/**
* Creates the edit form for the widget.
* Creates the edit form for the widget.
*
*
*/
*/
function form($instance){
function form($instance){
//Defaults
//Defaults
$instance = wp_parse_args( (array) $instance, array('title'=>'') );
$instance = wp_parse_args( (array) $instance, array('title'=>'') );
$this->form_html($instance);
$this->form_html($instance);
}
}
}// END class
}// END class
/**
/**
* Register Hierarchical Categories widget.
* Register Hierarchical Categories widget.
*
*
* Calls 'widgets_init' action after the widget has been registered.
* Calls 'widgets_init' action after the widget has been registered.
*/
*/
function HierCatInit() {
function HierCatInit() {
register_widget('HierCatWidget');
register_widget('HierCatWidget');
}
}
/*
/*
* Initialize both widgets
* Initialize both widgets
*/
*/
add_action('widgets_init', 'HierCatInit');
add_action('widgets_init', 'HierCatInit');
add_action('widgets_init', 'HierPageInit');
add_action('widgets_init', 'HierPageInit');
?>
?>