/**
 * 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;
}
 /**
  * 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);
 }
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;
}
Beispiel #4
0
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;
}
/**
 * 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;
}
 /**
  * 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;
 }
 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);
 }
Beispiel #8
0
 /**
  * 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);
 }
 /**
  * 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));
         }
     }
 }
Beispiel #10
0
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;
}
Beispiel #11
0
 /**
  * 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);
 }
 /**
  * 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());
 }
Beispiel #13
0
 /**
  * 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);
 }
 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;
 }
 /**
  * @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);
     }
 }
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;
}
Beispiel #17
0
 /**
  * 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;
 }
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;
}
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;
}
Beispiel #20
0
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;
}
 /**
  * Outputs the HTML for this widget.
  *
  * @param array, An array of standard parameters for widgets in this theme 
  * @param array, An array of settings for this widget instance 
  * @return void Echoes it's output
  **/
 function widget($args, $instance)
 {
     extract($args, EXTR_SKIP);
     // Only run on hierarchical post types
     $post_types = get_post_types(array('hierarchical' => true));
     if (!is_singular($post_types) && !apply_filters('be_subpages_widget_display_override', false)) {
         return;
     }
     // Find top level parent and create path to it
     global $post;
     $parents = array_reverse(get_ancestors($post->ID, 'page'));
     $parents[] = $post->ID;
     $parents = apply_filters('be_subpages_widget_parents', $parents);
     // Build a menu listing top level parent's children
     $args = array('child_of' => $parents[0], 'parent' => $parents[0], 'sort_column' => 'menu_order', 'post_type' => get_post_type());
     $depth = 1;
     $subpages = get_pages(apply_filters('be_subpages_widget_args', $args, $depth));
     // If there are pages, display the widget
     if (empty($subpages)) {
         return;
     }
     echo $before_widget;
     global $be_subpages_is_first;
     $be_subpages_is_first = true;
     // Build title
     $title = esc_attr($instance['title']);
     if (1 == $instance['title_from_parent']) {
         $title = get_the_title($parents[0]);
         if (1 == $instance['title_link']) {
             $title = '<a href="' . get_permalink($parents[0]) . '">' . apply_filters('be_subpages_widget_title', $title) . '</a>';
         }
     }
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     if (!isset($instance['deep_subpages'])) {
         $instance['deep_subpages'] = 0;
     }
     if (!isset($instance['nest_subpages'])) {
         $instance['nest_subpages'] = 0;
     }
     // Print the tree
     $this->build_subpages($subpages, $parents, $instance['deep_subpages'], $depth, $instance['nest_subpages']);
     echo $after_widget;
 }
 public static function get_top_level_taxonomy($id = 0)
 {
     global $post;
     if (empty($id)) {
         $id = $post->ID;
     }
     $terms = wp_get_object_terms($id, self::$post_type_tax, array('fields' => 'ids'));
     if (!$terms) {
         return false;
     }
     $ancestors = get_ancestors($terms[0], self::$post_type_tax);
     if (empty($ancestors)) {
         $term_id = $terms[0];
     } else {
         $term_id = reset($ancestors);
     }
     return get_term_by('id', $term_id, self::$post_type_tax);
 }
function acf_location_rules_match_page_level($match, $rule, $options)
{
    if (!isset($options['post_id'])) {
        return $match;
    }
    $post_type = get_post_type($options['post_id']);
    $page_parent = 0;
    if (!$options['page_parent']) {
        $post = get_post($options['post_id']);
        $page_parent = $post->post_parent;
    } else {
        $page_parent = $options['page_parent'];
    }
    if (!$page_parent) {
        $page_level = 1;
    } else {
        $ancestors = get_ancestors($options['page_parent'], $post_type);
        $page_level = count($ancestors) + 2;
    }
    $operator = $rule['operator'];
    $value = $rule['value'];
    switch ($operator) {
        case '==':
            $match = $page_level == $value;
            break;
        case '!=':
            $match = $page_level != $value;
            break;
        case '<':
            $match = $page_level < $value;
            break;
        case '<=':
            $match = $page_level <= $value;
            break;
        case '>=':
            $match = $page_level >= $value;
            break;
        case '>':
            $match = $page_level > $value;
            break;
    }
    // end switch
    return $match;
}
function acf_location_rule_match_category_ancestor($match, $rule, $options)
{
    // most of this copied directly from acf post category rule
    $terms = $options['post_taxonomy'];
    $data = acf_decode_taxonomy_term($rule['value']);
    $term = get_term_by('slug', $data['term'], $data['taxonomy']);
    if (!$term && is_numeric($data['term'])) {
        $term = get_term_by('id', $data['term'], $data['taxonomy']);
    }
    // this is where it's different than ACf
    // get terms so we can look at the parents
    if (is_array($terms)) {
        foreach ($terms as $index => $term_id) {
            $terms[$index] = get_term_by('id', intval($term_id), $term->taxonomy);
        }
    }
    if (!is_array($terms) && $options['post_id']) {
        $terms = wp_get_post_terms(intval($options['post_id']), $term->taxonomy);
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $terms = array_filter($terms);
    $match = false;
    // collect a list of ancestors
    $ancestors = array();
    if (count($terms)) {
        foreach ($terms as $term_to_check) {
            $ancestors = array_merge(get_ancestors($term_to_check->term_id, $term->taxonomy));
        }
        // end foreach terms
    }
    // end if
    // see if the rule matches any term ancetor
    if ($term && in_array($term->term_id, $ancestors)) {
        $match = true;
    }
    if ($rule['operator'] == '!=') {
        // reverse the result
        $match = !$match;
    }
    return $match;
}
Beispiel #25
0
function main_visual()
{
    $id = get_the_id();
    $mainVisual = get_field("mainVisual", $id);
    $pageTitle = get_the_title($id);
    if ($mainVisual) {
        echo "<h1 class=\"titleWithBG\">";
        echo "<img src='" . $mainVisual . "'>";
        echo "</h1>";
    } else {
        $ancestors = get_ancestors($id, "page");
        if ($ancestors[0]) {
            $mainVisual = get_field("mainVisual", $ancestors[0]);
            echo "<h1 class=\"titleWithBG\">";
            echo "<img src='" . $mainVisual . "'>";
            echo "</h1>";
        } else {
            echo "<h1 class=\"title col-xs-12\">" . $pageTitle . "</h1>";
        }
    }
}
Beispiel #26
0
 /**
  * Parent page
  * @return object name, url
  */
 public function parent_page()
 {
     $parent_name = null;
     $parent_url = null;
     if (!is_null(get_post())) {
         $id = get_post()->ID;
         $post_type = get_post()->post_type;
         $parents = get_ancestors($id, $post_type);
         if (!empty($parents)) {
             $parent_id = $parents[0];
             $parent_post = get_post($parent_id);
             if ($parent_id) {
                 $parent_name = $parent_post->post_title;
                 $parent_url = get_permalink($parent_id);
             } else {
                 $parent_name = null;
                 $parent_url = null;
             }
         }
     }
     return (object) array('name' => $parent_name, 'url' => $parent_url);
 }
Beispiel #27
0
function mnt_get_formatted_page_array()
{
    global $suffusion_pages_array;
    if (isset($suffusion_pages_array) && $suffusion_pages_array != null) {
        return $suffusion_pages_array;
    }
    $ret = array();
    $pages = get_pages('sort_column=menu_order');
    if ($pages != null) {
        foreach ($pages as $page) {
            if (is_null($suffusion_pages_array)) {
                $ret[$page->ID] = array("title" => $page->post_title, "depth" => count(get_ancestors($page->ID, 'page')));
            }
        }
    }
    if ($suffusion_pages_array == null) {
        $suffusion_pages_array = $ret;
        return $ret;
    } else {
        return $suffusion_pages_array;
    }
}
Beispiel #28
0
function contents_cfinfobox()
{
    //set up variables
    $pageid = get_the_ID();
    //get page ID
    $objectfetch = get_option("widget_cfinfobox");
    //object types from setting
    $objectposttype = $objectfetch['posttype'];
    $objectkeyword = $objectfetch['category'];
    $objectelsetext = $objectfetch['elsetext'];
    $ancestorarray = get_ancestors($pageid, $objectposttype);
    //foreach($ancestorarray as $ancestor){
    //echo $ancestor}
    //do they match?)
    if (in_array($objectkeyword, $ancestorarray)) {
        echo '<h3>' . get_the_title() . '</h3>';
        //display page title
        echo '<p>' . the_meta() . '</p>';
    } else {
        echo $objectelsetext;
    }
}
function sfhiv_draw_page_navigation($post_ids, $args = array())
{
    extract($args);
    if (!is_array($post_ids)) {
        $post_ids = array($post_ids);
    }
    $ids_to_show = array();
    ?>
<nav><?php 
    foreach ($post_ids as $ID) {
        array_push($ids_to_show, $ID);
        if (!isset($show_children) || $show_children) {
            $children = get_pages(apply_filters('sfhiv_filter_args', array("parent" => $ID, "hierarchical" => 0, "post_type" => get_post_type($ID))));
            foreach ($children as $child) {
                array_push($ids_to_show, $child->ID);
            }
        }
        $parents = get_ancestors($ID, get_post_type($ID));
        if (!isset($show_parents) || $show_parents) {
            foreach ($parents as $parent) {
                array_push($ids_to_show, $parent);
            }
        }
        if (!isset($show_siblings) || $show_siblings) {
            if (count($parents) > 0) {
                $parent_ID = $parents[0];
                $siblings = get_pages(apply_filters('sfhiv_filter_args', array("parent" => $parent_ID, "hierarchical" => 0, "post_type" => get_post_type($ID))));
                foreach ($siblings as $sibling) {
                    array_push($ids_to_show, $sibling->ID);
                }
            }
        }
    }
    wp_page_menu(array_merge($args, array('show_home' => false, 'sort_column' => 'menu_order', 'include' => implode(",", $ids_to_show), 'post_type' => get_post_type($ID), 'walker' => new SFHIV_Post_Type_Walker_Menu())));
    ?>
</nav><?php 
}
Beispiel #30
0
/**
 * Ajax handler to add a tag.
 *
 * @since 3.1.0
 *
 * @global WP_List_Table $wp_list_table
 */
function wp_ajax_add_tag()
{
    global $wp_list_table;
    check_ajax_referer('add-tag', '_wpnonce_add-tag');
    $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
    $tax = get_taxonomy($taxonomy);
    if (!current_user_can($tax->cap->edit_terms)) {
        wp_die(-1);
    }
    $x = new WP_Ajax_Response();
    $tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST);
    if (!$tag || is_wp_error($tag) || !($tag = get_term($tag['term_id'], $taxonomy))) {
        $message = __('An error has occurred. Please reload the page and try again.');
        if (is_wp_error($tag) && $tag->get_error_message()) {
            $message = $tag->get_error_message();
        }
        $x->add(array('what' => 'taxonomy', 'data' => new WP_Error('error', $message)));
        $x->send();
    }
    $wp_list_table = _get_list_table('WP_Terms_List_Table', array('screen' => $_POST['screen']));
    $level = 0;
    if (is_taxonomy_hierarchical($taxonomy)) {
        $level = count(get_ancestors($tag->term_id, $taxonomy, 'taxonomy'));
        ob_start();
        $wp_list_table->single_row($tag, $level);
        $noparents = ob_get_clean();
    }
    ob_start();
    $wp_list_table->single_row($tag);
    $parents = ob_get_clean();
    $x->add(array('what' => 'taxonomy', 'supplemental' => compact('parents', 'noparents')));
    $x->add(array('what' => 'term', 'position' => $level, 'supplemental' => (array) $tag));
    $x->send();
}