• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP get_ancestors函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: categoryRender

function categoryRender($id, $taxonomy)
{
    $category = get_term_by('id', $id, $taxonomy);
    $ancestors = get_ancestors($category->term_id, 'lagraphics_categories');
    $catName = $category->name;
    if (count($ancestors)) {
        foreach ($ancestors as $key => $value) {
            $cat = get_term_by('id', $value, 'lagraphics_categories');
            $catName = $cat->name . ' > ' . $catName;
        }
    }
    return $catName;
}
开发者ID:soshace,项目名称:designer-plugin-wp4,代码行数:13,代码来源:designer_admin.php


示例17: generate_toc

 /**
  * Generates toc as html string
  * @return string
  */
 public function generate_toc($top_parent_id = 0)
 {
     $options = get_option(MakeItStatic::CONFIG_TABLE_FIELD);
     //get the web server address first so we know what to use for the link
     $ws_target_address = $options["ws_address"];
     $ws_target_address = rtrim($ws_target_address, "/ ");
     //trim incase we have the trailing slash
     $toc_link_prefix = "";
     if ($options["toc_link_prefix"]) {
         $toc_link_prefix = $options["toc_link_prefix"];
         $toc_link_prefix = self::DIRECTORY_SEPARATOR . trim($toc_link_prefix, "/ /\n");
     }
     //start building the TOC this is a recursive function that determines the level of each of the links
     $this->build_toc($top_parent_id, 0, 0);
     $toc_html = "";
     //now generate the static string
     if (count($this->toc_rows)) {
         foreach ($this->toc_rows as &$toc_row) {
             $toc_level = $toc_row['level'];
             if (!$toc_level) {
                 //skip level 0
                 continue;
             }
             $title = $toc_row['page_data']->post_title;
             $id = $toc_row['page_data']->ID;
             $parent_id = $toc_row['parent_id'];
             $link_body = "";
             //so get the hierarchy and generate the post name here so the front controller can later tokenize the following.
             $page_ancestors = get_ancestors($id, 'page');
             $page_ancestors = array_reverse($page_ancestors);
             foreach ($page_ancestors as $page_ancestor) {
                 $current_page_ancestor = get_page($page_ancestor);
                 $link_body .= self::DIRECTORY_SEPARATOR . $current_page_ancestor->post_name;
             }
             $link_body .= self::DIRECTORY_SEPARATOR . $toc_row['page_data']->post_name . self::DIRECTORY_SEPARATOR;
             $link = $ws_target_address . $toc_link_prefix . $link_body;
             //we need these identifier in case we want to use javascript to expand or collapse the divs
             $current_path = str_replace(self::DIRECTORY_SEPARATOR, "_", $toc_link_prefix . $link_body);
             if ($toc_level == 1) {
                 $parent_path = $current_path;
             }
             ob_start();
             include $this->view_dir . 'toc_view.php';
             $contents = ob_get_contents();
             ob_clean();
             $toc_html .= $contents;
         }
     }
     return $toc_html;
 }
开发者ID:rvbd,项目名称:make-it-static,代码行数:54,代码来源:toc_generator.php


示例18: newMoreLink

function newMoreLink($article_id, $section_id)
{
    $taxonomy = 'section';
    $article = get_post($article_id);
    $section = get_term($section_id, $taxonomy);
    $section_ancestors = get_ancestors($section->term_id, $taxonomy);
    krsort($section_ancestors);
    $permalink = '<a class="button moreLink" href="/documentation/';
    foreach ($section_ancestors as $ancestor) {
        $section_ancestor = get_term($ancestor, $taxonomy);
        $permalink .= $section_ancestor->slug . '/';
    }
    $permalink .= $section->slug . '/' . $article->post_name . '/" >' . 'Read more &rarr;' . '</a>';
    echo $permalink;
}
开发者ID:alex-storojenko,项目名称:eerp_plugin,代码行数:15,代码来源:articles-permalink.php


示例19: 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


示例20: bb_menu

function bb_menu($args)
{
    // last updated 23/10/2014
    is_array($args) ? extract($args) : parse_str($args);
    //set defaults
    if (!isset($menu) && strpos($args, '=') == false) {
        $menu = $args;
    }
    if (!isset($menu)) {
        return;
    }
    if (!isset($modal)) {
        $modal = 'tnz_modal';
    }
    if (!isset($li_class)) {
        $li_class = 's-no-class';
    }
    if (!isset($class)) {
        $class = 's-no-class';
    }
    unset($ourmenu);
    global $post;
    $menu_name = $menu;
    if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
        $menu = wp_get_nav_menu_object($locations[$menu_name]);
        $menu_items = wp_get_nav_menu_items($menu->term_id);
        foreach ((array) $menu_items as $key => $menu_item) {
            $ancestors = get_ancestors($post->ID, 'page');
            $li_class = in_array($menu_item->object_id, $ancestors) || $post->ID == $menu_item->object_id || is_home() && get_option('page_for_posts') == $menu_item->object_id ? 'active' : '';
            if ($menu_item->menu_item_parent == 0) {
                $ourmenu .= '<li class="' . $li_class . ' menu-item menu-item-' . $menu_item->ID . ' ' . $menu_item->classes[0] . '">';
                if (strpos($menu_item->url, $modal) > 0) {
                    $ourmenu .= '<a data-reveal-id="' . $modal . '_' . $menu_item->object_id . '" href="#">' . $menu_item->title . '</a>';
                } else {
                    $ourmenu .= '<a class="' . $class . '" href="' . $menu_item->url . '">' . $menu_item->title . '</a>';
                }
                $ourmenu .= '</li>';
            }
        }
    }
    if (isset($ourmenu)) {
        echo $ourmenu;
    }
    return;
}
开发者ID:BrownBox,项目名称:charlie,代码行数:45,代码来源:menus.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_and_set_current_group函数代码示例发布时间:2022-05-15
下一篇:
PHP get_alt_col函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap