当前位置: 首页>>代码示例>>PHP>>正文


PHP get_term_children函数代码示例

本文整理汇总了PHP中get_term_children函数的典型用法代码示例。如果您正苦于以下问题:PHP get_term_children函数的具体用法?PHP get_term_children怎么用?PHP get_term_children使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_term_children函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: wpdm_categories_tree

 function wpdm_categories_tree($parent = 0, $selected = array())
 {
     $categories = get_terms('wpdmcategory', array('hide_empty' => 0, 'parent' => $parent));
     $checked = "";
     foreach ($categories as $category) {
         if ($selected) {
             foreach ($selected as $ptype) {
                 if ($ptype->term_id == $category->term_id) {
                     $checked = "checked='checked'";
                     break;
                 } else {
                     $checked = "";
                 }
             }
         }
         echo '<li><a href="' . get_term_link($category) . '"> ' . $category->name . ' </a>';
         $termchildren = get_term_children($category->term_id, 'wpdmcategory');
         if ($termchildren) {
             echo "<ul>";
             wpdm_categories_tree($category->term_id, $selected);
             echo "</ul>";
         }
         echo "</li>";
     }
 }
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:25,代码来源:class.Categories.php

示例2: fw_ext_portfolio_get_listing_categories

/**
 * @param int|array $term_ids
 *
 * @return array|WP_Error
 */
function fw_ext_portfolio_get_listing_categories($term_ids)
{
    $args = array('hide_empty' => false);
    if (is_numeric($term_ids)) {
        $args['parent'] = $term_ids;
    } elseif (is_array($term_ids)) {
        $args['include'] = $term_ids;
    }
    $ext_portfolio_settings = fw()->extensions->get('portfolio')->get_settings();
    $taxonomy = $ext_portfolio_settings['taxonomy_name'];
    $categories = get_terms($taxonomy, $args);
    if (!is_wp_error($categories) && !empty($categories)) {
        if (count($categories) === 1) {
            $categories = array_values($categories);
            $categories = get_terms($taxonomy, array('parent' => $categories[0]->term_id, 'hide_empty' => false));
        }
        foreach ($categories as $key => $category) {
            $children = get_term_children($category->term_id, $taxonomy);
            $categories[$key]->children = $children;
            //remove empty categories
            if ($category->count == 0 && (is_wp_error($children) || empty($children))) {
                unset($categories[$key]);
            }
        }
        return $categories;
    }
    return array();
}
开发者ID:northpen,项目名称:northpen,代码行数:33,代码来源:helpers.php

示例3: get_products_in_category

 /**
  * Get all product ids in a category (and its children)
  *
  * @param  int $category_id
  * @return array
  */
 public function get_products_in_category($category_id)
 {
     $term_ids = get_term_children($category_id, 'product_cat');
     $term_ids[] = $category_id;
     $product_ids = get_objects_in_term($term_ids, 'product_cat');
     return array_unique(apply_filters('woocommerce_report_sales_by_category_get_products_in_category', $product_ids, $category_id));
 }
开发者ID:dabodude,项目名称:woocommerce,代码行数:13,代码来源:class-wc-report-sales-by-category.php

示例4: getChildIds

 /**
  * @return array
  */
 public function getChildIds()
 {
     if ($this->childIds === null) {
         $childIds = (array) get_term_children($this->id, $this->taxonomy);
         $this->childIds = array_map('intval', $childIds);
     }
     return $this->childIds;
 }
开发者ID:kraftmark,项目名称:oowp,代码行数:11,代码来源:TermModel.php

示例5: wpdm_cat_has_child

/**
 * @usage Check if a download manager category has child
 * @param $parent
 * @return bool
 */
function wpdm_cat_has_child($parent)
{
    $termchildren = get_term_children($parent, 'wpdmcategory');
    if (count($termchildren) > 0) {
        return true;
    }
    return false;
}
开发者ID:bitflipper1,项目名称:ghcontracting,代码行数:13,代码来源:wpdm-core.php

示例6: getChildren

 public function getChildren()
 {
     $children = array();
     print_r($this->_taxonomy);
     foreach (get_term_children($this->term_id, $this->taxonomy) as $term_id) {
         $children[] = static::forge($term_id, $this->taxonomy);
     }
     return $children;
 }
开发者ID:adriend,项目名称:morepress,代码行数:9,代码来源:Term.php

示例7: widget

    public function widget($args, $instance)
    {
        $title = apply_filters('widget_title', $instance['title']);
        echo $args['before_widget'];
        if (!empty($title)) {
            echo $args['before_title'] . $title . $args['after_title'];
        }
        $cat_args = array('parent' => $instance['parent'], 'number' => $instance['number'], 'hide_empty' => $instance['hide_empty'], 'orderby' => $instance['orderby'], 'order' => $instance['order']);
        $categories = get_terms('question_category', $cat_args);
        ?>

        <ul id="ap-categories-widget" class="ap-cat-wid clearfix">
			<?php 
        foreach ($categories as $key => $category) {
            $sub_cat_count = count(get_term_children($category->term_id, 'question_category'));
            ?>
                <li class="clearfix">
					<a class="ap-cat-image" href="<?php 
            echo get_category_link($category);
            ?>
"><?php 
            echo ap_get_category_image($category->term_id);
            ?>
</a>
					<a class="ap-cat-wid-title" href="<?php 
            echo get_category_link($category);
            ?>
">
						<?php 
            echo $category->name;
            ?>
                    </a>
                    <div class="ap-cat-count">
						<span><?php 
            printf(_n('%d Question', '%d Questions', $category->count, 'categories-for-anspress'), $category->count);
            ?>
</span>
						<?php 
            if ($sub_cat_count > 0) {
                ?>
							<span><?php 
                printf(__('%d Child', 'categories-for-anspress'), $sub_cat_count);
                ?>
</span>
						<?php 
            }
            ?>
                    </div>
                </li>
			<?php 
        }
        ?>
        </ul>

		<?php 
        echo $args['after_widget'];
    }
开发者ID:cowlicker12,项目名称:categories-for-anspress,代码行数:57,代码来源:categories-widget.php

示例8: wcapf_get_term_childs

 function wcapf_get_term_childs($term_id, $taxonomy)
 {
     $transient_name = 'wcapf_term_childs_' . md5(sanitize_key($taxonomy) . sanitize_key($term_id));
     if (false === ($term_childs = get_transient($transient_name))) {
         $term_childs = get_term_children($term_id, $taxonomy);
         set_transient($transient_name, $term_childs, WCAPF_CACHE_TIME);
     }
     return (array) $term_childs;
 }
开发者ID:wptailor,项目名称:wc-ajax-product-filter,代码行数:9,代码来源:functions.php

示例9: post_is_in_descendant_category

function post_is_in_descendant_category($cats, $_post = null)
{
    foreach ((array) $cats as $cat) {
        $descendants = get_term_children((int) $cat, 'category');
        if ($descendants && in_category($descendants, $_post)) {
            return true;
        }
    }
    return false;
}
开发者ID:PDM-OpenGov,项目名称:opengov_consultations,代码行数:10,代码来源:func.php

示例10: is_in_descendant

 public function is_in_descendant($post_id, $parent_term)
 {
     foreach ((array) $parent_term as $pt) {
         $pt = get_term_by('slug', $pt, 'category');
         $child_terms = get_term_children($pt->term_id, $this->tax_name);
         if ($child_terms && in_category($child_terms, $post_id)) {
             return true;
         }
     }
     return false;
 }
开发者ID:cibulka,项目名称:cibulka-wp-plugin-base,代码行数:11,代码来源:Post_Terms.php

示例11: wpsc_products_by_category

 /**
  * wpsc_products_by_category function.
  *
  * @access public
  * @param mixed $query
  * @return void
  */
 function wpsc_products_by_category($query)
 {
     global $wpdb;
     $q = $query->query_vars;
     // Category stuff for nice URLs
     if (!empty($q['wpsc_product_category']) && !$query->is_singular) {
         $q['taxonomy'] = 'wpsc_product_category';
         $q['term'] = $q['wpsc_product_category'];
         $in_cats = '';
         $join = " INNER JOIN {$wpdb->term_relationships}\n\t\t\t\tON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)\n\t\t\tINNER JOIN {$wpdb->term_taxonomy}\n\t\t\t\tON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id)\n\t\t\t";
         if (isset($q['meta_key'])) {
             $join .= " INNER JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id) ";
         }
         $whichcat = " AND {$wpdb->term_taxonomy}.taxonomy = '{$q['taxonomy']}' ";
         $term_data = get_term_by('slug', $q['term'], $q['taxonomy']);
         if (is_object($term_data)) {
             $in_cats = array($term_data->term_id);
         }
         if ('0' != get_option('show_subcatsprods_in_cat') && is_object($term_data)) {
             $term_children_data = get_term_children($term_data->term_id, $q['taxonomy']);
             $in_cats = array_reverse(array_merge($in_cats, $term_children_data));
         }
         if (is_array($in_cats)) {
             $in_cats = "'" . implode("', '", $in_cats) . "'";
             $whichcat .= "AND {$wpdb->term_taxonomy}.term_id IN ({$in_cats})";
         }
         $post_type_object = get_post_type_object('wpsc-product');
         $permitted_post_statuses = current_user_can($post_type_object->cap->edit_posts) ? "'" . implode("', '", apply_filters('wpsc_product_display_status', array('publish'))) . "'" : "'publish'";
         $whichcat .= " AND {$wpdb->posts}.post_status IN ({$permitted_post_statuses}) ";
         $groupby = "{$wpdb->posts}.ID";
         $this->sql_components['join'] = $join;
         $this->sql_components['fields'] = "{$wpdb->posts}.*, {$wpdb->term_taxonomy}.term_id, {$wpdb->term_relationships}.term_order";
         $this->sql_components['group_by'] = $groupby;
         //what about ordering by price
         if (isset($q['meta_key']) && '_wpsc_price' == $q['meta_key']) {
             $whichcat .= " AND {$wpdb->postmeta}.meta_key = '_wpsc_price'";
         } else {
             $this->sql_components['order_by'] = "{$wpdb->term_taxonomy}.term_id";
             // Term Taxonomy ID Ordering
             if ($q['orderby'] == 'menu_order') {
                 if ($term_data) {
                     $this->sql_components['order_by'] = "{$wpdb->term_relationships}.term_order ASC";
                 }
             }
         }
         $this->sql_components['where'] = $whichcat;
         add_filter('posts_join', array(&$this, 'join_sql'));
         add_filter('posts_where', array(&$this, 'where_sql'));
         add_filter('posts_fields', array(&$this, 'fields_sql'));
         add_filter('posts_orderby', array(&$this, 'order_by_sql'));
         add_filter('posts_groupby', array(&$this, 'group_by_sql'));
     }
 }
开发者ID:dreamteam111,项目名称:dreamteam,代码行数:60,代码来源:wpsc-products-by-category.php

示例12: widget

    public function widget($args, $instance)
    {
        $title = apply_filters('widget_title', $instance['title']);
        echo $args['before_widget'];
        if (!empty($title)) {
            echo $args['before_title'] . $title . $args['after_title'];
        }
        $cat_args = array('parent' => $instance['parent'], 'number' => $instance['number'], 'hide_empty' => false, 'orderby' => $instance['orderby'], 'order' => $instance['order']);
        $categories = get_terms('question_category', $cat_args);
        ?>
			<ul class="ap-categories-list">
				<?php 
        foreach ($categories as $key => $category) {
            $sub_cat_count = count(get_term_children($category->term_id, 'question_category'));
            ?>
					<li>
						<a class="term-title ap-icon-category" href="<?php 
            echo get_category_link($category);
            ?>
"><?php 
            echo $category->name;
            ?>
							
							<span><?php 
            echo $category->count;
            ?>
</span>
							<?php 
            if ($sub_cat_count > 0) {
                ?>
								<i class="ap-icon-arrow-down"></i>
							<?php 
            }
            ?>
						</a>						
						<?php 
            if ($sub_cat_count > 0) {
                echo '<div class="ap-term-sub">';
                echo '<div class="sub-cat-count">' . $sub_cat_count . ' ' . __('Sub Categories', 'ap') . '</div>';
                ap_child_cat_list($category->term_id);
                echo '</div>';
            }
            ?>
			
					</li>
				<?php 
        }
        ?>
			</ul>
		<?php 
        echo $args['after_widget'];
    }
开发者ID:jessor,项目名称:anspress,代码行数:52,代码来源:categories.php

示例13: _wpbdp_padded_count

/**
 * @since 2.3
 * @access private
 */
function _wpbdp_padded_count(&$term)
{
    global $wpdb;
    $found = false;
    $count = intval(wp_cache_get('term-padded-count-' . $term->term_id, 'wpbdp', false, $found));
    if (!$count && !$found) {
        $tree_ids = array_merge(array($term->term_id), get_term_children($term->term_id, WPBDP_CATEGORY_TAX));
        $tt_ids = $wpdb->get_col($wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id IN (" . implode(',', $tree_ids) . ") AND taxonomy = %s", WPBDP_CATEGORY_TAX));
        $query = $wpdb->prepare("SELECT COUNT(DISTINCT r.object_id) FROM {$wpdb->term_relationships} r INNER JOIN {$wpdb->posts} p ON p.ID = r.object_id WHERE p.post_status = %s and p.post_type = %s AND term_taxonomy_id IN (" . implode(',', $tt_ids) . ")", 'publish', WPBDP_POST_TYPE);
        $count = apply_filters('_wpbdp_padded_count', intval($wpdb->get_var($query)), $term);
    }
    $term->count = $count;
}
开发者ID:Nedick,项目名称:stzagora-website,代码行数:17,代码来源:templates-ui.php

示例14: wl_entity_type_taxonomy_get_term_children

/**
 * Get the children types of given term.
 *
 * @param mixes $term Term ID (e.g. 12) or slug (e.g. 'creative-work') or name (e.g. 'CreativeWork').
 * @param string $by Search key. Must be one of: 'id', 'slug', 'name', or 'term_taxonomy_id'.
 */
function wl_entity_type_taxonomy_get_term_children($term, $by = 'name')
{
    // TODO: test this method
    // NOTE: WP taxonomy terms can have only one parent. This is a WP limit.
    $children_terms = array();
    $term = get_term_by($by, $term, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
    if (isset($term->term_id)) {
        $children_ids = get_term_children($term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
        foreach ($children_ids as $children_id) {
            $children_terms[] = get_term($children_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
        }
    }
    return $children_terms;
}
开发者ID:Byrlyne,项目名称:wordlift-plugin,代码行数:20,代码来源:wordlift_entity_type_taxonomy.php

示例15: wp_all_export_check_children_assign

function wp_all_export_check_children_assign($parent, $taxonomy, $term_ids = array())
{
    $is_latest_child = true;
    $children = get_term_children($parent, $taxonomy);
    if (count($children) > 0) {
        foreach ($children as $child) {
            if (in_array($child, $term_ids)) {
                $is_latest_child = false;
                break;
            }
        }
    }
    return $is_latest_child;
}
开发者ID:hikaram,项目名称:wee,代码行数:14,代码来源:wp_all_export_check_children_assign.php


注:本文中的get_term_children函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。