本文整理汇总了PHP中get_term_children函数的典型用法代码示例。如果您正苦于以下问题:PHP get_term_children函数的具体用法?PHP get_term_children怎么用?PHP get_term_children使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_term_children函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: get_weekdays
protected function get_weekdays($instance)
{
global $week_mapping;
$weekdays_cat = get_category_by_path(isset($instance['weekday_category']) ? $instance['weekday_category'] : 'timetable');
$weekdays = array_map(function ($t) {
return get_category($t);
}, get_term_children($weekdays_cat->term_id, $weekdays_cat->taxonomy));
$result = [];
foreach ($weekdays as $weekday) {
$index = $week_mapping[strtoupper($weekday->cat_name)];
$result[$index] = $weekday;
}
ksort($result);
return $result;
}
开发者ID:hjbolide,项目名称:wordpress_roster,代码行数:15,代码来源:roster_widget.php
示例17: test_should_rebuild_split_term_taxonomy_hierarchy
/**
* @ticket 30335
*/
public function test_should_rebuild_split_term_taxonomy_hierarchy()
{
global $wpdb;
register_taxonomy('wptests_tax_3', 'post');
register_taxonomy('wptests_tax_4', 'post', array('hierarchical' => true));
$t1 = wp_insert_term('Foo1', 'wptests_tax_3');
$t2 = wp_insert_term('Foo1 Parent', 'wptests_tax_4');
$t3 = wp_insert_term('Foo1', 'wptests_tax_4', array('parent' => $t2['term_id']));
// Manually modify because shared terms shouldn't naturally occur.
$wpdb->update($wpdb->term_taxonomy, array('term_id' => $t1['term_id']), array('term_taxonomy_id' => $t3['term_taxonomy_id']), array('%d'), array('%d'));
$th = _get_term_hierarchy('wptests_tax_4');
$new_term_id = _split_shared_term($t1['term_id'], $t3['term_taxonomy_id']);
$t2_children = get_term_children($t2['term_id'], 'wptests_tax_4');
$this->assertEquals(array($new_term_id), $t2_children);
}
开发者ID:Benrajalu,项目名称:philRaj,代码行数:18,代码来源:splitSharedTerm.php
示例18: ubik_places_list
function ubik_places_list($term = null)
{
$tax = 'places';
// Allows us to pass an explicit term and achieve the same functionality
if (empty($term) || $term == '') {
$term = get_term_by('slug', get_query_var('term'), $tax);
}
// Check again
if (!empty($term)) {
$places = array();
// Get direct descendents of the current term
$children = get_term_children($term->term_id, $tax);
// Get direct descendents of the parent of the current term; get_term_children is not appropriate here
$siblings = get_terms($tax, array('parent' => $term->parent));
// Get ancestors of the current term
$ancestors = get_ancestors($term->term_id, $tax);
// Get the highest ancestor of the current term
if (!empty($ancestors)) {
$patriarch = get_term(end($ancestors), $tax);
} else {
$patriarch = $term;
}
// Unite the whole family (the current term plus all ancestors)
$family = $ancestors;
$family[] = $term->term_id;
// Setup children query
if (!empty($children)) {
// Attempt to limit terms with an abundance of children; this is pure guess work
if (count($children) >= 25 && !empty($ancestors)) {
$depth = 1;
} else {
$depth = 2;
}
$places[] = array('name' => 'children', 'title' => sprintf(__('Places in %s', 'ubik'), apply_filters('ubik_places_title', $term->name)), 'args' => array('child_of' => $term->term_id, 'depth' => $depth, 'show_count' => 1, 'hide_empty' => 0, 'taxonomy' => $tax, 'title_li' => '', 'show_option_none' => __('No places found', 'ubik'), 'echo' => 0));
// If there are no childen at least show the parent tree; no different than breadcrumbs, really
} elseif (!empty($ancestors)) {
$places[] = array('name' => 'ancestors', 'title' => sprintf(__('%s in context', 'ubik'), apply_filters('ubik_places_title', $term->name)), 'args' => array('depth' => 0, 'taxonomy' => $tax, 'include' => $family, 'title_li' => '', 'show_option_none' => __('No places found', 'ubik'), 'echo' => 0));
}
// Setup sibling query; conditions: more than 2 siblings and not a top-level place
if (!empty($siblings) && count($siblings) >= 2 && !empty($ancestors)) {
$places[] = array('name' => 'siblings', 'title' => __('Related places', 'ubik'), 'args' => array('child_of' => $term->parent, 'depth' => 1, 'taxonomy' => $tax, 'exclude' => $term->term_id, 'title_li' => '', 'show_option_none' => __('No places found', 'ubik'), 'echo' => 0));
}
// Places index
$places[] = array('name' => 'index', 'title' => __('Places index', 'ubik'), 'args' => array('child_of' => 0, 'depth' => 1, 'show_count' => 1, 'taxonomy' => $tax, 'title_li' => '', 'show_option_none' => __('No places found', 'ubik'), 'echo' => 0));
}
// Return the array of pseudo-widgets to the theme
return $places;
}
开发者ID:synapticism,项目名称:ubik-places,代码行数:48,代码来源:ubik-places-core.php
示例19: joinCatChilds
function joinCatChilds($value, $index)
{
$catid = get_term_by('name', $value, 'ad_cat');
$catid = $catid->term_id;
$tax = 'tax' . $index;
if (!empty($catid)) {
(array) ($include_cats[] = $catid);
$descendants = get_term_children((int) $catid, 'ad_cat');
foreach ($descendants as $k => $v) {
$include_cats[] = $v;
}
$include_cats = '"' . implode('", "', $include_cats) . '"';
$join .= " AND {$tax}.term_id IN ({$include_cats}) ";
}
return $join;
}
开发者ID:ugurbastan,项目名称:swe-574-group4,代码行数:16,代码来源:dynamic_counter.php
示例20: tfuse_portfolio
function tfuse_portfolio($atts)
{
extract(shortcode_atts(array('category' => '', 'columns' => 'three-column'), $atts));
wp_register_script('isotope', tfuse_get_file_uri('/js/isotope.pkgd.min.js'), array('jquery'), '1.0', true);
wp_enqueue_script('isotope');
$output = '';
if ($category != 0) {
$tax = 'group';
$term = get_term_by('id', $category, $tax);
$term_children = get_term_children($category, $tax);
$args = array('posts_per_page' => -1, 'post_type' => 'portfolio', 'tax_query' => array(array('taxonomy' => $tax, 'field' => 'id', 'terms' => $category)));
$query = new WP_Query($args);
$posts = $query->get_posts();
if (!empty($term)) {
$output .= '<div class="shortcode-portfolio">';
if (tfuse_options('enable_portfolio_filter', true)) {
$output .= '<div class="wrapp-categories-gallery">
<ul id="categories" class="gallery-categories">';
if (!empty($term_children)) {
$output .= '<li class="categories-item active" data-category="' . $term->slug . '"><div class="check-category"><span></span></div>' . $term->name . '</li>';
foreach ($term_children as $id) {
$term_child = get_term_by('id', $id, $tax);
$output .= '<li class="categories-item" data-category="' . $term_child->slug . '"><div class="check-category"><span></span></div>' . $term_child->name . '</li>';
}
}
$output .= '</ul>
<a class="prev" id="categories-prev" href="#"><i class="tficon-shevron-left"></i></a>
<a class="next" id="categories-next" href="#"><i class="tficon-shevron-right"></i></a>
</div>';
}
$output .= '<section class="gallery">' . '' . '
<ul id="gallery-list" class="gallery-list ' . $columns . '">';
if (!empty($posts)) {
foreach ($posts as $post) {
$output .= '<li class="gallery-item" data-category="' . tfuse_get_portfolio_categories_list($post->ID) . '">
<div class="gallery-img">' . tfuse_get_portfolio_thumbnail($post->ID, $columns) . '</div>
' . tfuse_get_portfolio_gallery($post->ID) . '
</li>';
}
}
$output .= '</ul>';
$output .= '</section></div>';
}
}
return $output;
}
开发者ID:part-time-project,项目名称:italians,代码行数:46,代码来源:portfolio.php
注:本文中的get_term_children函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论