articlesss.com. // Страница плагина на русском языке находится здесь. */ function artdir_get_version(){ return '0.9.1'; } add_action('init', 'artdir_textdomain'); function artdir_textdomain() { load_plugin_textdomain('article-directory', 'wp-content/plugins/article-directory'); } function artdir_plugin_description($string) { if (trim($string) == 'Displays the structured list of categories (like in article directory), which can be easily customized with CSS.') $string = __('Displays the structured list of categories (like in article directory), which can be easily customized with CSS. See an example at articlesss.com.', 'article-directory'); return $string; } add_filter('pre_kses', 'artdir_plugin_description'); function article_directory() { // получаем все опции $options = get_option('article_directory'); // проверяем каждую опцию // если опция есть, то присваиваем её переменной, если нет (:), то дефолт $exclude_cats = isset($options['exclude_cats']) ? $options['exclude_cats'] : 0; $show_parent_count = isset($options['show_parent_count']) ? (int) $options['show_parent_count'] : 1; $show_child_count = isset($options['show_child_count']) ? (int) $options['show_child_count'] : 1; $hide_empty = isset($options['hide_empty']) ? (int) $options['hide_empty'] : 0; $desc_for_parent_title = isset($options['desc_for_parent_title']) ? (int) $options['desc_for_parent_title'] : 1; $desc_for_child_title = isset($options['desc_for_child_title']) ? (int) $options['desc_for_child_title'] : 1; $child_hierarchical = isset($options['child_hierarchical']) ? (int) $options['child_hierarchical'] : 1; $column_count = isset($options['column_count']) ? $options['column_count'] : 3; $sort_direction = isset($options['sort_direction']) ? (int) $options['sort_direction'] : 0; $no_child_alert = isset($options['no_child_alert']) ? (int) $options['no_child_alert'] : 1; $show_child = isset($options['show_child']) ? (int) $options['show_child'] : 1; $maximum_child = isset($options['maximum_child']) ? $options['maximum_child'] : 0; $forgot_the_cat = isset($options['forgot_the_cat']) ? (int) $options['forgot_the_cat'] : 1; $sel_only_one_cat = isset($options['sel_only_one_cat']) ? (int) $options['sel_only_one_cat'] : 1; $kinderloss = isset($options['kinderloss']) ? (int) $options['kinderloss'] : 1; $hide_blocks = isset($options['hide_blocks']) ? (int) $options['hide_blocks'] : 1; $using_wp_version = isset($options['using_wp_version']) ? (int) $options['using_wp_version'] : 1; $cat_block_height = isset($options['cat_block_height']) ? $options['cat_block_height'] : 200; $hide_tags_field = isset($options['hide_tags_field']) ? (int) $options['hide_tags_field'] : 0; $publish_terms = isset($options['publish_terms']) ? (int) $options['publish_terms'] : 0; $publish_terms_text = isset($options['publish_terms_text']) ? $options['publish_terms_text'] : ''; $exclude_cat = array($exclude_cats); global $wpdb; $cal_tree = array(); if (!$column_count) $column_count = 1; function get_wpvers() { global $wp_version; preg_match("/\d\.\d/i", $wp_version, $match); // wpmu - increment version by 1.0 to match wp if (strpos($wp_version, 'wordpress-mu') !== false) { $match[0] = $match[0] + 1.0; } return $match[0]; } if (get_wpvers() == '2.1' || get_wpvers() == '2.2') { error_reporting(0); $wpdb->show_errors = false; } global $rssfeeds; $feed = ''; if ($rssfeeds) { $feed = 'RSS'; $show_parent_count = 0; $show_child_count = 0; } if (get_wpvers() < '2.3') { // for WP < 2.3 $parent_cats = $wpdb->get_results("SELECT * FROM " . $wpdb->categories . " WHERE category_parent = 0 " . ( count($exclude_cat) ? ' AND cat_ID NOT IN (' . implode(',', $exclude_cat) . ') ' : '' ) . " ORDER BY cat_name"); foreach ($parent_cats as $parent) { $summ = "SELECT SUM(category_count) FROM " . $wpdb->categories . " WHERE category_parent = " . $parent->cat_ID; $child_summ = mysql_result(mysql_query($summ),0); $catid = $wpdb->get_var("SELECT cat_ID FROM " . $wpdb->categories . " WHERE category_parent = " . $parent->cat_ID); //определяем ID подрубрики 1-го уровня $sub_child_summ = $wpdb->get_var("SELECT SUM(category_count) FROM " . $wpdb->categories . " WHERE category_parent = " . $catid); //считаем кол-во статей в подрубрике 2-го уровня $cat_name = get_the_category_by_ID($parent->cat_ID); $descr = sprintf(__("View all posts filed under %s"), $cat_name); if ($desc_for_parent_title == 1) { if (empty($parent->category_description)) { $descr = sprintf(__("View all posts filed under %s"), $cat_name); } else { $descr = $parent->category_description; } } $child_summ += $parent->category_count; //прибавляем к сумме родительской рубрики сумму в подрубрике 1-го уровня $child_summ += $sub_child_summ; //прибавляем к сумме родительской рубрики сумму в подрубрике 2-го уровня if ($show_parent_count == 1) { $parent_count = ' (' . $child_summ . ')'; } else { $parent_count = ''; } // перехват вывода ob_start(); wp_list_cats( ( count($exclude_cat) ? 'exclude=' . implode(',', $exclude_cat) : '' ) . '&optioncount=' . $show_child_count . '&hide_empty=' . $hide_empty . '&use_desc_for_title=' . $desc_for_child_title . '&child_of=' . $parent->cat_ID . '&hierarchical=1&feed=' . $feed); $echo = ob_get_contents(); ob_end_clean(); $cal_tree[] = array( 'cat' => array( 'href' => get_category_link($parent->cat_ID), 'title' => $descr, 'name' => $cat_name, 'count' => $parent_count ), 'cats'=> $echo ); } } // end for WP < 2.3 else { // for WP >= 2.3 $parent_cats = $wpdb->get_results("SELECT * FROM " . $wpdb->term_taxonomy . " term_taxonomy LEFT JOIN " . $wpdb->terms . " terms ON terms.term_id = term_taxonomy.term_id WHERE term_taxonomy.taxonomy = 'category' AND term_taxonomy.parent = 0 " . ( count($exclude_cat) ? ' AND terms.term_id NOT IN (' . implode(',', $exclude_cat) . ') ' : '' ) . " ORDER BY terms.name"); foreach ($parent_cats as $parent) { $summ = "SELECT SUM(count) FROM " . $wpdb->term_taxonomy . " WHERE taxonomy = 'category' AND parent = " . $parent->term_id; $child_summ = mysql_result(mysql_query($summ),0); //считаем кол-во статей в подрубрике 1-го уровня $catid = $wpdb->get_var("SELECT term_ID FROM " . $wpdb->term_taxonomy . " WHERE taxonomy = 'category' AND parent = " . $parent->term_id); //определяем ID подрубрики 1-го уровня $sub_child_summ = $wpdb->get_var("SELECT SUM(count) FROM " . $wpdb->term_taxonomy . " WHERE taxonomy = 'category' AND parent = " . $catid); //считаем кол-во статей в подрубрике 2-го уровня $cat_name = get_the_category_by_ID($parent->term_id); $descr = sprintf(__("View all posts filed under %s"), $cat_name); if ($desc_for_parent_title == 1) { if (empty($parent->description)) { $descr = sprintf(__("View all posts filed under %s"), $cat_name); } else { $descr = $parent->description; } } $child_summ += $parent->count; //прибавляем к сумме родительской рубрики сумму в подрубрике 1-го уровня $child_summ += $sub_child_summ; //прибавляем к сумме родительской рубрики сумму в подрубрике 2-го уровня if ($show_parent_count == 1) { $parent_count = ' (' . $child_summ . ')'; } else { $parent_count = ''; } $cal_tree[] = array( 'cat' => array( 'href' => get_category_link($parent->term_id), 'title' => $descr, 'name' => $cat_name, 'count' => $parent_count ), 'cats'=> wp_list_categories( ( count($exclude_cat) ? 'exclude=' . implode(',', $exclude_cat) : '' ) . '&show_count=' . $show_child_count . '&hide_empty=' . $hide_empty . '&use_desc_for_title=' . $desc_for_child_title . '&child_of=' . $parent->term_id . '&title_li=&hierarchical=' . $child_hierarchical . '&echo=0&feed=' . $feed) ); } } // end for WP >= 2.3 $_tree = array(); $count = count($cal_tree); if ($sort_direction) { $line_count = ceil( $count / $column_count ); $limit = $count - $line_count * $column_count % $count; for ($i = 0; $i < $count; $i++) { $index = floor($i / $line_count) + ($limit && $i > $limit ? 1 : 0); if (!isset($_tree[$index])) { $_tree[$index] = array(); } $_tree[$index][] = &$cal_tree[$i]; } } else { for ($i = 0; $i < $count; $i++) { $index = $i % $column_count; if (!isset($_tree[$index])) { $_tree[$index] = array(); } $_tree[$index][] = &$cal_tree[$i]; } } if (count($_tree)) { echo '
Article Directory v by Dimox.
@import \'categories.css\';
<?php if (function_exists(\'article_directory\')) article_directory(); ?>
* * *
More detailed informations on this plugin can be found at Article Directory homepage.
If you find this plugin useful, please tell your blog readers about it.