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


PHP get_ancestors函数代码示例

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


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

示例1: ac_portfolio_post_type_link

/**
 * Filter to allow portfolio_cat in the permalinks for portfolio.
 *
 * @param  string  $permalink The existing permalink URL.
 * @param  WP_Post $post
 * @return string
 */
function ac_portfolio_post_type_link($permalink, $post)
{
    // Abort if post is not a portfolio.
    if ($post->post_type !== 'portfolio') {
        return $permalink;
    }
    // Abort early if the placeholder rewrite tag isn't in the generated URL.
    if (false === strpos($permalink, '%')) {
        return $permalink;
    }
    // Get the custom taxonomy terms in use by this post.
    $terms = get_the_terms($post->ID, 'portfolio_cat');
    if (!empty($terms)) {
        usort($terms, '_usort_terms_by_ID');
        // order by ID
        $category_object = apply_filters('ac_portfolio_post_type_link_portfolio_cat', $terms[0], $terms, $post);
        $category_object = get_term($category_object, 'portfolio_cat');
        $portfolio_cat = $category_object->slug;
        if ($category_object->parent) {
            $ancestors = get_ancestors($category_object->term_id, 'portfolio_cat');
            foreach ($ancestors as $ancestor) {
                $ancestor_object = get_term($ancestor, 'portfolio_cat');
                $portfolio_cat = $ancestor_object->slug . '/' . $portfolio_cat;
            }
        }
    } else {
        // If no terms are assigned to this post, use a string instead (can't leave the placeholder there)
        $portfolio_cat = _x('uncategorized', 'slug', 'axiscomposer');
    }
    $find = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%post_id%', '%category%', '%portfolio_cat%');
    $replace = array(date_i18n('Y', strtotime($post->post_date)), date_i18n('m', strtotime($post->post_date)), date_i18n('d', strtotime($post->post_date)), date_i18n('H', strtotime($post->post_date)), date_i18n('i', strtotime($post->post_date)), date_i18n('s', strtotime($post->post_date)), $post->ID, $portfolio_cat, $portfolio_cat);
    $permalink = str_replace($find, $replace, $permalink);
    return $permalink;
}
开发者ID:axisthemes,项目名称:axiscomposer,代码行数:41,代码来源:functions-ac-portfolio.php

示例2: getAncestorsAttribute

 /**
  * Get the ancestors.
  *
  * @uses \get_ancestors()
  *
  * @return \Illuminate\Support\Collection|\Luminous\Bridge\Term\Entity[]
  */
 protected function getAncestorsAttribute()
 {
     $ancestors = array_map(function ($id) {
         return WP::term($id, $this->type);
     }, get_ancestors($this->id, $this->original->taxonomy, 'taxonomy'));
     return new Collection($ancestors);
 }
开发者ID:hrslash,项目名称:luminous,代码行数:14,代码来源:HierarchicalEntity.php

示例3: acf_location_rules_match_page_ancestor

function acf_location_rules_match_page_ancestor($match, $rule, $options)
{
    // this code is with inspiration from
    // acf_location::rule_match_page_parent()
    // check parents recursively to see if any
    // matches the location value
    if (isset($options['page_parent']) && $options['page_parent']) {
        $page_parent = $options['page_parent'];
        unset($options['page_parent']);
    } elseif (isset($options['post_id']) && $options['post_id']) {
        $post = get_post($options['post_id']);
        $page_parent = $post->post_parent;
    }
    $ancestors = array();
    if ($page_parent) {
        $ancestors = get_ancestors($page_parent, 'page');
        $ancestors[] = $page_parent;
    }
    if ($rule['operator'] == "==") {
        $match = in_array($rule['value'], $ancestors);
    } elseif ($rule['operator'] == "!=") {
        $match = !in_array($rule['value'], $ancestors);
    }
    return $match;
}
开发者ID:Hube2,项目名称:acf-filters-and-functions,代码行数:25,代码来源:acf-page-ancestor-location-rule.php

示例4: inherited_featured_image

function inherited_featured_image($page = NULL)
{
    if (is_numeric($page)) {
        $page = get_post($page);
    } elseif (is_null($page)) {
        $page = isset($GLOBALS['post']) ? $GLOBALS['post'] : NULL;
    }
    if (!$page instanceof WP_Post) {
        return false;
    }
    // if we are here we have a valid post object to check,
    // get the ancestors
    $ancestors = get_ancestors($page->ID, $page->post_type);
    if (empty($ancestors)) {
        return false;
    }
    // ancestors found, let's check if there are featured images for them
    global $wpdb;
    $metas = $wpdb->get_results("SELECT post_id, meta_value\n\t\t\t\t\t\t\tFROM {$wpdb->postmeta}\n\t\t\t\t\t\t\tWHERE meta_key = '_thumbnail_id'\n\t\t\t\t\t\t\tAND post_id IN (" . implode(',', $ancestors) . ");");
    if (empty($metas)) {
        return false;
    }
    // extract only post ids from meta values
    $post_ids = array_map('intval', wp_list_pluck($metas, 'post_id'));
    // compare each ancestor and if return meta value for nearest ancestor
    foreach ($ancestors as $ancestor) {
        if (($i = array_search($ancestor, $post_ids, TRUE)) !== FALSE) {
            //return $post_ids;
            return $metas[$i]->post_id;
        }
    }
    return false;
}
开发者ID:netAction,项目名称:foto-penz-theme,代码行数:33,代码来源:header.php

示例5: categories_chain

/**
 * Generate chains of categories
 */
function categories_chain()
{
    $output = '';
    $category = 'goods_category';
    /**
     * If the current page is product page, use get_the_terms() to get ID
     */
    if (is_single()) {
        global $post;
        $product_terms = get_the_terms($post->ID, $category);
        if ($product_terms) {
            // fix invalid argument supplied for foreach() if there is no category for the product
            foreach ($product_terms as $p) {
                $category_id = $p->term_id;
            }
        }
    } else {
        /**
         * If current page is category page, use get_queried_object() to get ID
         */
        $category_id = get_queried_object()->term_id;
    }
    $ancestors_reverse = get_ancestors($category_id, $category);
    $ancestors = array_reverse($ancestors_reverse);
    //var_dump($ancestors);
    foreach ($ancestors as $a) {
        $ancestor = get_term($a, $category);
        $ancestor_name = $ancestor->name;
        $ancestor_link = '<a href="' . get_term_link($ancestor->slug, $category) . '">' . $ancestor_name . '</a> &gt; ';
        $output .= $ancestor_link;
    }
    return $output;
}
开发者ID:jazzindizzin,项目名称:Quality-Timber-Doors,代码行数:36,代码来源:breadcrumbs.php

示例6: get_terms_for_site

 /**
  * Return the terms for the given type.
  *
  * @param int $site_id Blog ID.
  *
  * @return array
  */
 public function get_terms_for_site($site_id)
 {
     $out = [];
     switch_to_blog($site_id);
     $taxonomy_object = get_taxonomy($this->taxonomy_name);
     if (!current_user_can($taxonomy_object->cap->edit_terms)) {
         $terms = [];
     } else {
         $terms = get_terms($this->taxonomy_name, ['hide_empty' => FALSE]);
     }
     foreach ($terms as $term) {
         if (is_taxonomy_hierarchical($this->taxonomy_name)) {
             $ancestors = get_ancestors($term->term_id, $this->taxonomy_name);
             if (!empty($ancestors)) {
                 foreach ($ancestors as $ancestor) {
                     $parent_term = get_term($ancestor, $this->taxonomy_name);
                     $term->name = $parent_term->name . '/' . $term->name;
                 }
             }
         }
         $out[$term->term_taxonomy_id] = esc_html($term->name);
     }
     restore_current_blog();
     uasort($out, 'strcasecmp');
     return $out;
 }
开发者ID:inpsyde,项目名称:multilingual-press,代码行数:33,代码来源:Mlp_Term_Translation_Presenter.php

示例7: start_el

 function start_el(&$output, $item, $depth, $args)
 {
     $classes = empty($item->classes) ? array() : (array) $item->classes;
     $current_object = get_queried_object();
     $has_children_after = $args->has_children_after ? $args->has_children_after : '';
     if ($args->level && $args->level > $depth) {
         $level = $args->level - 1;
     } else {
         $level = $depth;
     }
     $target_object_id = '#';
     if ($current_object->has_archive && get_post($item->object_id)->post_name == $current_object->rewrite['slug']) {
         $classes[] = 'current-menu-item';
     }
     if (is_page($current_object) && (in_array($item->object_id, get_ancestors($current_object->ID, 'page')) || in_array(get_post($item->object_id)->post_parent, get_ancestors($current_object->ID, 'page')))) {
         $classes[] = 'current-menu-item';
     }
     if (is_single($current_object)) {
         $c_post_type = get_post_type($current_object);
         if (get_post($item->object_id)->post_name == get_post_type_object($c_post_type)->rewrite['slug']) {
             $classes[] = 'current-menu-item';
         }
     }
     $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item));
     if ($args->has_children && $depth == 0) {
         !empty($class_names) and $class_names = ' class="' . esc_attr($class_names) . ' has_children dropdown"';
         if (!$args->has_children_after) {
             $args->has_children_after = '<i class="fa fa-caret-down visible-xs visible-sm"></i>';
         } else {
             $args->has_children_after = $has_children_after;
         }
     } else {
         !empty($class_names) and $class_names = ' class="' . esc_attr($class_names) . '"';
         if (isset($args->has_children_after)) {
             $args->has_children_after = '';
         }
     }
     $attributes = '';
     !empty($item->attr_title) and $attributes .= ' title="' . esc_attr($item->attr_title) . '"';
     !empty($item->target) and $attributes .= ' target="' . esc_attr($item->target) . '"';
     !empty($item->xfn) and $attributes .= ' rel="' . esc_attr($item->xfn) . '"';
     !empty($item->url) and $attributes .= ' href="' . esc_attr($item->url) . '"';
     if (defined('SCROLLBY') && SCROLLBY) {
         if (is_single($item->object_id) || is_page($item->object_id)) {
             $target_object_id .= get_post_field('post_name', $item->object_id);
         }
         $attributes .= ' data-target="' . $target_object_id . '"';
     }
     // insert description for top level elements only
     // you may change this
     $description = (!empty($item->description) and 0 == $depth) ? '<span class="desc">' . esc_attr($item->description) . '</span>' : '';
     $title = apply_filters('the_title', $item->title, $item->ID);
     if ($level == $depth) {
         $output .= "<li id='menu-item-{$item->ID}' {$class_names}>";
         $item_output = $args->before . "<a {$attributes}>" . $args->link_before . $title . '</a>' . $args->link_after . $args->has_children_after . $description . $args->after;
     }
     // Since $output is called by reference we don't need to return anything.
     $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
 }
开发者ID:quangnpd,项目名称:jobshop_web,代码行数:59,代码来源:Bootstrap_Nav_Walker.php

示例8: renderTermBreadcrumb

 /**
  * Render term breadcrumb
  * 
  * @return string
  * 
  * @access protected
  */
 protected function renderTermBreadcrumb()
 {
     list($term, $taxonomy) = explode('|', AAM_Core_Request::post('id'));
     $ancestors = array_reverse(get_ancestors($term, $taxonomy, 'taxonomy'));
     $breadcrumb = array();
     foreach ($ancestors as $id) {
         $breadcrumb[] = get_term($id, $taxonomy)->name;
     }
     return implode(' &Gt; ', $breadcrumb);
 }
开发者ID:DrLeeroyPhD,项目名称:sidekicks,代码行数:17,代码来源:Post.php

示例9: term_ancestors

 /**
  * Add parent erms items for a term
  *
  * @since 4.0.0
  * @param string $taxonomy
  */
 private function term_ancestors($term_id, $taxonomy)
 {
     $ancestors = get_ancestors($term_id, $taxonomy);
     $ancestors = array_reverse($ancestors);
     foreach ($ancestors as $ancestor) {
         $ancestor = get_term($ancestor, $taxonomy);
         if (!is_wp_error($ancestor) && $ancestor) {
             $this->_add_item('link_format', $ancestor->name, get_term_link($ancestor));
         }
     }
 }
开发者ID:xav335,项目名称:sfnettoyage,代码行数:17,代码来源:class-cherry-woo-breadcrumbs.php

示例10: get_ancestors

function get_ancestors($id, $taxonomy)
{
    $html = [];
    if ($terms = \get_ancestors($id, $taxonomy)) {
        foreach ($terms as $term) {
            $term = get_term($term, $taxonomy);
            $html[] = sprintf('<span class="p-category"><a href="%s" rel="tag">%s</a></span>', get_term_link($term), $term->name);
        }
    }
    return $html;
}
开发者ID:synapticism,项目名称:ubik,代码行数:11,代码来源:terms.php

示例11: widget

 /**
  * Output HTML
  *
  * @since    1.0.9.9
  * @version  1.3.13
  */
 function widget($args, $instance)
 {
     // Requirements check
     $post_types = get_post_types(array('hierarchical' => true));
     if (!is_singular($post_types) || apply_filters('wmhook_widgets_' . 'wm_subnav' . '_disabled', false, $args, $instance)) {
         return;
     }
     // Helper variables
     global $post;
     $output = '';
     $instance = wp_parse_args($instance, array('order' => 'menu_order', 'parent' => '', 'title' => ''));
     $post = is_home() ? get_post(get_option('page_for_posts')) : $post;
     $parents = get_ancestors($post->ID, get_post_type($post));
     // Get the direct parent or the highest level parent
     if ($instance['parent'] && !empty($parents)) {
         $grandparent = $parents[0];
     } elseif (!$instance['parent'] && !empty($parents)) {
         $grandparent = end($parents);
     } else {
         $grandparent = '';
     }
     // Set the parent page title as a widget title when it was left empty
     if (!trim($instance['title'])) {
         if ($grandparent) {
             $instance['title'] = '<a href="' . esc_url(get_permalink($grandparent)) . '">' . get_the_title($grandparent) . '</a>';
         } else {
             $instance['title'] = '<a href="' . esc_url(get_permalink($post->ID)) . '">' . get_the_title($post->ID) . '</a>';
         }
         $instance['title'] = apply_filters('wmhook_widgets_' . 'wm_subnav' . '_title_auto', $instance['title'], $args, $instance);
     }
     // Subpages or siblings
     $args_children = array('post_type' => get_post_type($post), 'title_li' => '', 'depth' => 3, 'sort_column' => $instance['order'], 'echo' => false, 'child_of' => $post->ID);
     if ($grandparent) {
         $args_children['child_of'] = $grandparent;
     }
     $children = wp_list_pages((array) apply_filters('wmhook_widgets_' . 'wm_subnav' . '_wp_list_pages_args', $args_children, $args, $instance));
     // If there are no pages, don't display the widget
     if (empty($children)) {
         return;
     }
     // Processing
     // Before widget
     $output .= $args['before_widget'];
     // Title
     if (trim($instance['title'])) {
         $output .= $args['before_title'] . apply_filters('widget_title', $instance['title'], $instance, $this->id_base, $args) . $args['after_title'];
     }
     $output .= '<ul class="sub-nav">' . $children . '</ul>';
     // After widget
     $output .= $args['after_widget'];
     // Output
     echo apply_filters('wmhook_widgets_' . 'wm_subnav' . '_output', $output, $args, $instance);
 }
开发者ID:pab44,项目名称:pab44,代码行数:59,代码来源:w-subnav.php

示例12: ancestors

 /**
  * Get ancestors
  *
  * @return array PostInspector objects
  */
 public function ancestors()
 {
     if (!$this->isHierarchical()) {
         return false;
     }
     $ancestorIds = get_ancestors($this->post->ID, $this->post->post_type);
     if (!$ancestorIds) {
         return false;
     }
     $query = new WP_Query(array('post_type' => $this->post->post_type, 'posts_per_page' => -1, 'post__in' => $ancestorIds, 'orderby' => 'post_parent', 'order' => 'DESC'));
     return $this->makePostInspectorObjects($query->get_posts());
 }
开发者ID:elcontraption,项目名称:wp-post-inspector,代码行数:17,代码来源:PostInspector.php

示例13: widget

 /**
  * Output widget.
  *
  */
 public function widget($args, $instance)
 {
     global $wp_query, $post;
     $orderby = isset($instance['orderby']) ? $instance['orderby'] : $this->settings['orderby']['std'];
     $hide_empty = isset($instance['hide_empty']) ? $instance['hide_empty'] : $this->settings['hide_empty']['std'];
     $list_args = array('taxonomy' => 'product_cat', 'hide_empty' => $hide_empty);
     // Menu Order
     $list_args['menu_order'] = false;
     if ($orderby == 'order') {
         $list_args['menu_order'] = 'asc';
     } else {
         $list_args['orderby'] = 'title';
     }
     // Setup Current Category
     $this->current_cat = false;
     if (is_tax('product_cat')) {
         $current_categ = $wp_query->queried_object;
         if ($current_categ->parent) {
             $this->current_cat = get_term($current_categ->parent);
         } else {
             $this->current_cat = $wp_query->queried_object;
         }
         $this->cat_ancestors = get_ancestors($this->current_cat->term_id, 'product_cat');
     }
     // Direct children are wanted
     $direct_children = get_terms('product_cat', array('fields' => 'ids', 'parent' => 0, 'hierarchical' => true, 'hide_empty' => false));
     // Gather siblings of ancestors
     $siblings = array();
     if ($this->cat_ancestors) {
         foreach ($this->cat_ancestors as $ancestor) {
             $ancestor_siblings = get_terms('product_cat', array('fields' => 'ids', 'parent' => $ancestor, 'hierarchical' => false, 'hide_empty' => false));
             $siblings = array_merge($siblings, $ancestor_siblings);
         }
     }
     $include = array_merge($direct_children);
     $list_args['include'] = implode(',', $include);
     if (empty($include)) {
         return;
     }
     $this->widget_start($args, $instance);
     include_once WC()->plugin_path() . '/includes/walkers/class-product-cat-list-walker.php';
     $list_args['walker'] = new WC_Product_Cat_List_Walker();
     $list_args['title_li'] = '';
     $list_args['pad_counts'] = 1;
     $list_args['show_option_none'] = __('No product categories exist.', 'woocommerce');
     $list_args['current_category'] = $this->current_cat ? $this->current_cat->term_id : '';
     $list_args['current_category_ancestors'] = $this->cat_ancestors;
     echo '<ul class="product-categories">';
     wp_list_categories(apply_filters('woocommerce_product_categories_widget_args', $list_args));
     echo '</ul>';
     $this->widget_end($args);
 }
开发者ID:aliomaster,项目名称:zero-project,代码行数:56,代码来源:widgets.php

示例14: wcapf_get_term_ancestors

 function wcapf_get_term_ancestors($term_id, $taxonomy)
 {
     $transient_name = 'wcafp_term_ancestors_' . md5(sanitize_key($taxonomy) . sanitize_key($term_id));
     if (false === ($term_ancestors = get_transient($transient_name))) {
         $term_ancestors = get_ancestors($term_id, $taxonomy);
         set_transient($transient_name, $term_ancestors);
     }
     // if found then add current term id to this array
     if (sizeof($term_ancestors) > 0) {
         array_push($term_ancestors, $term_id);
     }
     return (array) $term_ancestors;
 }
开发者ID:wptailor,项目名称:wc-ajax-product-filter,代码行数:13,代码来源:functions.php

示例15: get_top_level_product_category

 /**
  * @param $cat_id int product_cat term_id to find the top level parents of
  *
  * @return int top level parent term of submitted term
  *
  * @since 1.0
  */
 private static function get_top_level_product_category($cat_id)
 {
     $ancestors = get_ancestors($cat_id, self::$woocommerce_category_identifier, 'taxonomy');
     if (empty($ancestors)) {
         return (int) $cat_id;
     } else {
         $top_level_ancestor = end($ancestors);
         if (gettype($top_level_ancestor) !== 'integer') {
             error_log('WooCommerce_MajeMedia_Single_Top_Level_Category_Cart: ' . __FUNCTION__ . ': WP_Term Object is no longer returning integers for $term->term_id');
         }
         return (int) end($ancestors);
     }
 }
开发者ID:MajeMediaLLC,项目名称:WooCommerce_MajeMedia_Single_Top_Category_In_Cart,代码行数:20,代码来源:MMWC_STLCIC_Product_Information.php


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