function the_breadcrumb() { global $post; if (!is_home()) { echo '<div class="main_breadcrum"><p><a href="'. get_option('home') .'"> Home </a> > '; if ( is_category() || is_single() ) { foreach( ( get_the_category() ) as $category ) { if ( $category->cat_name != 'Slider' ) { echo '<a href="'. get_category_link( $category->term_id ) .'" title="'. $category->name .'" ' . '>'. $category->name .'</a> '; } } echo '</p></div>'; } elseif ( is_page() ) { if( $post->post_parent ){ $result = get_post_ancestors( $post->ID ); $title = get_the_title(); $output = ''; $anc = array_reverse( $result ); foreach ( $anc as $ancestor ) { $output .= '<a href="'. get_permalink( $ancestor ) .'" title="'. get_the_title( $ancestor ) .'">'.get_the_title( $ancestor ) .'</a> > '; } echo $output; echo '<strong title="'. $title .'"> '. $title .'</strong></p></div>'; } else { echo '<strong> '. get_the_title() .'</strong></p></div>'; } } } }
function ski_bg_class() { if ($post->post_parent) { $ancestors = get_post_ancestors($post->ID); $root = count($ancestors) - 1; $parent = $ancestors[$root]; } else { $parent = $post->ID; } function the_slug($id) { $post_data = get_post($id, ARRAY_A); $slug = $post_data['post_name']; return $slug; } switch (the_slug($parent)) { case "home": return "bg--home"; break; case "resorts": return "bg--resorts"; break; case "community": return "bg--community"; break; case "deals": return "bg--deals"; break; case "blog": return "bg--blog"; break; default: return "bg--default"; } }
function getpp_replace_hierarchicals($value) { $value = str_replace('this', get_the_ID(), $value); $value = str_replace('parent', wp_get_post_parent_id(get_the_ID()), $value); $value = str_replace('top', end(get_post_ancestors(get_the_ID())), $value); return $value; }
function tool_private_is_private_post($post_id) { $go_private = get_option(TOOL_PRIVATE_OPTIONS_GO_PRIVATE); if ($go_private && $go_private == "1") { return true; } else { if ($go_private && $go_private == "2") { $private_items = get_option(TOOL_PRIVATE_OPTIONS_ITEMS . "-" . get_current_lang()); if (!empty($private_items)) { $parent_ids = get_post_ancestors($post_id); $private_items = explode(",", $private_items); if (in_array($post_id, $private_items)) { return true; } else { foreach ($parent_ids as $parent_id) { if (in_array($parent_id, $private_items)) { return true; } } } } } } return false; }
function bb_param_pages($settings, $value) { $output = ''; $output .= '<select name="' . $settings['param_name'] . '" class="wpb_vc_param_value wpb-input wpb-select ' . $settings['param_name'] . ' ' . $settings['type'] . '">'; if (is_array($value)) { $value = isset($value['value']) ? $value['value'] : array_shift($value); } $pages = get_pages('hierarchical=2'); foreach ($pages as $page) { $option_label = get_the_title($page->ID); $option_value = $page->ID; $ancestors = get_post_ancestors($page->ID); $title_prefix = ''; for ($i = 0; count($ancestors) > $i; $i++) { $title_prefix .= '-'; } $selected = ''; if ($value !== '' && (string) $option_value === (string) $value) { $selected = ' selected="selected"'; } $output .= '<option value="' . $option_value . '"' . $selected . '>' . $title_prefix . ' ' . $option_label . '</option>'; } $output .= '</select>'; return $output; }
function genesis_page_checklist($name = '', $selected = array()) { $pages = get_pages(); $name = esc_attr($name); // home link if (in_array('home', (array) $selected)) { $checked = 'checked'; } else { $checked = ''; } $checkboxes = '<li><label class="selectit"><input type="checkbox" name="' . $name . '[]" value="home" ' . $checked . ' /> Home</label></li>' . "\n"; // other pages foreach ((array) $pages as $page) { if (in_array($page->ID, (array) $selected)) { $checked = 'checked'; } else { $checked = ''; } $ancestors = get_post_ancestors($page->ID); $indent = count((array) $ancestors); $indent = 'style="padding-left: ' . $indent * 15 . 'px;"'; $checkboxes .= '<li ' . $indent . '><label><input type="checkbox" name="' . $name . '[]" value="' . $page->ID . '" ' . $checked . ' /> '; $checkboxes .= esc_html(get_the_title($page->ID)) . '</label></li>' . "\n"; } echo $checkboxes; }
/** * Add page slug to body_class() classes if it doesn't exist * @param Array $classes array of already added classes * @return Array Array of classes to be added to the DOM */ function aiga_nebraska_body_class($classes) { global $wpdb, $post; // Add post/page slug if (is_single() || is_page() && !is_front_page()) { if (!in_array(basename(get_permalink()), $classes)) { $classes[] = basename(get_permalink()); } } if (is_page()) { if ($post->post_parent) { $parent = end(get_post_ancestors($current_page_id)); } else { $parent = $post->ID; } $post_data = get_post($parent, ARRAY_A); $classes[] = 'parent-' . $post_data['post_name']; } // remove stupid classes foreach ($classes as $key => $value) { if (strpos($value, 'parent-pageid') > -1 || strpos($value, 'page-template') > -1 || strpos($value, 'page-id') > -1) { unset($classes[$key]); } } return $classes; }
/** * Functions related to post types * */ function get_page_parent_title($post) { $parent = array_reverse(get_post_ancestors($post->ID)); $parent_data['id'] = $parent[0]; $parent_data['title'] = get_the_title($parent[0]); return $parent_data; }
/** * Get the ancestors. * * @uses \get_post_ancestors() * * @return \Illuminate\Support\Collection|\Luminous\Bridge\Post\Entity[] */ protected function getAncestorsAttribute() { $ancestors = array_map(function ($id) { return WP::post($id); }, get_post_ancestors($this->original)); return new Collection($ancestors); }
/** * The plugin bootstrap file * * This file is read by WordPress to generate the plugin information in the plugin * admin area. This file also includes all of the dependencies used by the plugin, * registers the activation and deactivation functions, and defines a function * that starts the plugin. * * @link http://errorstudio.co.uk * @since 1.0.0 * * @wordpress-plugin * Plugin Name: Rooftop Content Hierarchy * Plugin URI: http://errorstudio.co.uk * Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area. * Version: 1.0.0 * Author: Error * Author URI: http://errorstudio.co.uk * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt * Text Domain: rooftop-content-hierarchy * Domain Path: /languages */ function rooftop_add_content_hierarchy($response, $post, $request) { $child_post_args = array('post_parent' => $post->ID, 'post_type' => $post->post_type, 'numberposts' => -1, 'post_status' => array('publish'), 'orderby' => 'menu_order', 'order' => 'ASC'); if (apply_filters('rooftop_include_drafts', false)) { $child_post_args['post_status'][] = 'draft'; } $ancestor_posts = array_map(function ($id) { return get_post($id); }, get_post_ancestors($post)); $child_posts = get_children($child_post_args); $post_data = function ($p) { $post_data = array(); $post_data['id'] = $p->ID; $post_data['title'] = $p->post_title; $post_data['type'] = $p->post_type; $post_data['slug'] = $p->post_name; $post_data['embeddable'] = true; return $post_data; }; $post_object = get_post_type_object($post->post_type); if ($post_object && property_exists($post_object, 'rest_base')) { $rest_base = $post_object->rest_base; $rest_url = '/wp/v2/' . $rest_base; foreach ($ancestor_posts as $post) { $response->add_link('http://docs.rooftopcms.com/link_relations/ancestors', rest_url($rest_url . '/' . $post->ID), $post_data($post)); } foreach ($child_posts as $post) { $response->add_link('http://docs.rooftopcms.com/link_relations/children', rest_url($rest_url . '/' . $post->ID), $post_data($post)); } } return $response; }
public function shortcode_handler($atts, $content = null, $tag = '') { if (!is_post_type_hierarchical(get_post_type())) { return ''; } $ancestors = get_post_ancestors(get_the_ID()); if (!$ancestors) { return ''; } $r = []; $ancestors = array_reverse($ancestors); foreach ($ancestors as $ancestor) { $classes = ['hestia-ancestor', 'hestia-wrap', sprintf('post-%s', esc_attr($ancestor))]; $permalink = get_permalink($ancestor); $has_thumbnail = has_post_thumbnail($ancestor); if ($has_thumbnail) { // Because who doesn't love a properly alphabetized list? array_unshift($classes, 'has-post-thumbnail'); } $r[] = sprintf('<div class="%s">', implode(' ', $classes)); $r[] = sprintf('<a href="%1$s">', esc_attr($permalink)); if ($has_thumbnail) { $r[] = get_the_post_thumbnail($ancestor); } $r[] = get_the_title($ancestor); $r[] = '</a>'; $r[] = '</div>'; } return implode("\n", $r); }
function is_page_branch($pageID) { global $post; if (empty($pageID)) { return false; } if (!is_page() || is_front_page()) { return false; } if (is_page($pageID)) { return true; } if ($post->post_parent == 0) { return false; } $parents = get_post_ancestors($post); if (is_string($pageID)) { $test_id = get_page_by_path($pageID)->ID; } else { $test_id = (int) $pageID; } if (in_array($test_id, $parents)) { return true; } return false; }
/** * Breadcrumbs * - generates a list of breadcrumbs based off ancestors of current post * $post - current post object ***********************/ function occasions_breadcrumbs($post) { // get an array of ancestor IDs $parents = get_post_ancestors($post->ID); // reverse the order of the ancestor IDs so that the first is the oldest ancestor $parents = array_reverse($parents); // if there are no ancestors, then we are on the top level // if there are ancestors, lets generate some breadcrumbs if ($parents != NULL) { echo '<div class="oc_breadcrumb">'; // spit out a link to the ancestor followed by '>' foreach ($parents as $parent) { $the_parent = get_page($parent); echo '<a href="' . get_permalink($parent) . '">'; echo $the_parent->post_title; echo '</a>'; // if we are not at the current page, then leave a trailing '>' if ($post->ID != $parent) { echo '<span class="pipe">></span>'; } } // spit out the current page echo $post->post_title; echo '</div>'; } }
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { $post = $GLOBALS['post']; $top_ancestor = get_page(array_reverse(get_post_ancestors($post->ID))[0]); $title = get_the_title($top_ancestor->ID); extract($args); if ($post->post_parent) { $children = wp_list_pages("title_li=&child_of=" . $top_ancestor->ID . "&echo=0"); } else { $children = wp_list_pages("title_li=&child_of=" . $post->ID . "&echo=0"); } $title = apply_filters('widget_title', $title); if ($children) { echo $before_widget; if (!empty($title)) { echo $before_title . '<a href="' . get_permalink($top_ancestor->ID) . '">' . $title . '</a>' . $after_title; } ?> <ul class="nav-parent"> <?php echo $children; ?> </ul> <?php } echo $after_widget; }
/** * Plugin Name: Site Breadcrumbs * Plugin URI: https://wordpress.com * Description: Quickly add breadcrumbs to the single view of a hierarchical post type or a hierarchical taxonomy. * Author: Automattic * Version: 1.0 * Author URI: https://wordpress.com * License: GPL2 or later */ function jetpack_breadcrumbs() { $taxonomy = is_category() ? 'category' : get_query_var('taxonomy'); $is_taxonomy_hierarchical = is_taxonomy_hierarchical($taxonomy); $post_type = is_page() ? 'page' : get_query_var('post_type'); $is_post_type_hierarchical = is_post_type_hierarchical($post_type); if (!($is_post_type_hierarchical || $is_taxonomy_hierarchical) || is_front_page()) { return; } $breadcrumb = ''; if ($is_post_type_hierarchical) { $post_id = get_queried_object_id(); $ancestors = array_reverse(get_post_ancestors($post_id)); if ($ancestors) { foreach ($ancestors as $ancestor) { $breadcrumb .= '<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="' . esc_url(get_permalink($ancestor)) . '" itemprop="item"><span itemprop="name">' . esc_html(get_the_title($ancestor)) . '</span></a></span>'; } } $breadcrumb .= '<span class="current-page" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><span itemprop="name">' . esc_html(get_the_title($post_id)) . '</span></span>'; } elseif ($is_taxonomy_hierarchical) { $current = get_term(get_queried_object_id(), $taxonomy); if (is_wp_error($current)) { return; } if ($current->parent) { $breadcrumb = jetpack_get_term_parents($current->parent, $taxonomy); } $breadcrumb .= '<span class="current-category" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><span itemprop="name">' . esc_html($current->name) . '</span></span>'; } $home = '<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="' . esc_url(home_url('/')) . '" class="home-link" itemprop="item" rel="home"><span itemprop="name">' . esc_html__('Home', 'jetpack') . '</span></a></span>'; echo '<nav class="entry-breadcrumbs" itemscope itemtype="https://schema.org/BreadcrumbList">' . $home . $breadcrumb . '</nav>'; }
/** * @ticket 22882 */ function test_get_post_ancestors_with_falsey_values() { foreach (array(null, 0, false, '0', '') as $post_id) { $this->assertInternalType('array', get_post_ancestors($post_id)); $this->assertEquals(array(), get_post_ancestors($post_id)); } }
function the_breadcrumbs() { global $post; if (!is_home()) { echo "<a href='"; echo get_option('home'); echo "'>"; echo "Domov"; echo "</a>"; if (is_category() || is_single()) { echo " » "; $cats = get_the_category($post->ID); foreach ($cats as $cat) { // Get the URL of this category $category_link = get_category_link($cat->term_id); $output = "<a href='" . esc_url($category_link) . "'>" . $cat->cat_name . "</a> » "; echo $output; } if (is_single()) { the_title(); } } elseif (is_page()) { if ($post->post_parent) { $anc = get_post_ancestors($post->ID); $anc_link = get_page_link($post->post_parent); foreach ($anc as $ancestor) { $output = " » <a href=" . $anc_link . ">" . get_the_title($ancestor) . "</a> » "; } echo $output; the_title(); } else { echo ' » '; echo the_title(); } } } elseif (is_tag()) { single_tag_title(); } elseif (is_day()) { echo "Archive: "; the_time('F jS, Y'); echo '</li>'; } elseif (is_month()) { echo "Archive: "; the_time('F, Y'); echo '</li>'; } elseif (is_year()) { echo "Archive: "; the_time('Y'); echo '</li>'; } elseif (is_author()) { echo "Author's archive: "; echo '</li>'; } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { echo "Blogarchive: "; echo ''; } elseif (is_search()) { echo "Search results: "; } }
function get_top_parent_id() { if ($post->post_parent) { $ancestor = array_reverse(get_post_ancestors($post->ID)); return $ancestor[0]; } return $post->ID; }
/** * [UNFINISHED] Generates a breadcrumb or the current page. * * @return string The breadcrumb HTML */ function get_the_breadcrumb() { global $post; $str = '<ul id="breadcrumbs">'; if (!is_home()) { $str .= sprintf('<li><a href="%1$s">Home</a></li><li class="separator"> / </li>', home_url('/')); if (is_category() || is_single()) { $categories = get_the_category(); if ($categories) { $cats = array(); foreach (array_slice($categories, 0, 3) as $category) { $cats[] = sprintf('<li><a href="%1$s">%2$s</a></li>', get_category_link($category->term_id), $category->cat_name); } $str .= implode('<li class="separator"> / </li>', $cats); } if (is_single()) { $str .= '<li class="separator"> / </li><li>' . get_the_title() . '</li>'; } } elseif (is_page()) { if ($post->post_parent) { $anc = get_post_ancestors($post->ID); $title = get_the_title(); foreach ($anc as $ancestor) { $output = '<li><a href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li> <li class="separator">/</li>'; } $str .= $output; $str .= '<strong title="' . $title . ' "> ' . $title . '</strong>'; } else { $str .= '<li><strong> ' . get_the_title() . '</strong></li>'; } } } elseif (is_tag()) { single_tag_title(); } elseif (is_day()) { $str .= "<li>Archive for "; the_time('F jS, Y'); $str .= '</li>'; } elseif (is_month()) { $str .= "<li>Archive for "; the_time('F, Y'); $str .= '</li>'; } elseif (is_year()) { $str .= "<li>Archive for "; the_time('Y'); $str .= '</li>'; } elseif (is_author()) { $str .= "<li>Author Archive"; $str .= '</li>'; } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { $str .= "<li>Blog Archives"; $str .= '</li>'; } elseif (is_search()) { $str .= "<li>Search Results"; $str .= '</li>'; } $str .= '</ul>'; }
function breadcrumbs() { global $post; echo '<ol class="breadcrumb">'; if (!is_home()) { echo '<li><a href="'; echo get_option('home'); echo '">'; echo 'Home'; echo '</a></li>'; if (is_category() || is_single()) { echo '<li>'; the_category(' </li><li> '); if (is_single()) { echo '</li><li>'; the_title(); echo '</li>'; } } elseif (is_page()) { if ($post->post_parent) { $anc = get_post_ancestors($post->ID); $title = get_the_title(); foreach ($anc as $ancestor) { $output = '<li><a href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li> '; } echo $output; echo '<strong title="' . $title . '"> ' . $title . '</strong>'; } else { echo '<li><strong> ' . get_the_title() . '</strong></li>'; } } } elseif (is_tag()) { single_tag_title(); } elseif (is_day()) { echo "<li>Archive for "; the_time('F jS, Y'); echo '</li>'; } elseif (is_month()) { echo "<li>Archive for "; the_time('F, Y'); echo '</li>'; } elseif (is_year()) { echo "<li>Archive for "; the_time('Y'); echo '</li>'; } elseif (is_author()) { echo "<li>Author Archive"; echo '</li>'; } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { echo "<li>Blog Archives"; echo '</li>'; } elseif (is_search()) { echo "<li>Search Results"; echo '</li>'; } echo '</ol>'; }
function get_top_ancestor_id() { global $post; if ($post->post_parent) { $ancestors = array_reverse(get_post_ancestors($post->ID)); return $ancestors[0]; } return $post->ID; }
/** * make article hierarchy tree * @param $id post id * @return array */ function tree($id = null) { if (is_null($id)) { $id = get_the_ID(); } $ancestors = get_post_ancestors($id); $parent = empty($ancestors) ? $id : end($ancestors); return array(array('id' => $parent, 'url' => get_permalink($parent), 'title' => get_the_title($parent), 'children' => $this->children($parent))); }
function agatha_breadcrumb() { global $post; echo '<ul id="trilha">'; if (!is_home()) { echo '<li><a href="'; echo get_option('home'); echo '">'; echo 'Página inicial'; echo '</a></li><li class="separador"> / </li>'; if (is_category() || is_single()) { echo '<li>'; the_category(' </li><li class="separador"> / </li><li> '); if (is_single()) { echo '</li><li class="separador"> / </li><li>'; the_title(); echo '</li>'; } } elseif (is_page()) { if ($post->post_parent) { $anc = get_post_ancestors($post->ID); $title = get_the_title(); foreach ($anc as $ancestor) { $output = '<li><a href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li> <li class="separador">/</li>'; } echo $output; echo '<strong title="' . $title . '"> ' . $title . '</strong>'; } else { echo '<li><strong> ' . get_the_title() . '</strong></li>'; } } } elseif (is_tag()) { single_tag_title(); } elseif (is_day()) { echo "<li>Arquivo de "; the_time('j \\d\\e F \\d\\e Y'); echo '</li>'; } elseif (is_month()) { echo "<li>Arquivo de "; the_time('F \\d\\e Y'); echo '</li>'; } elseif (is_year()) { echo "<li>Arquivo de "; the_time('Y'); echo '</li>'; } elseif (is_author()) { echo "<li>Arquivo do autor"; echo '</li>'; } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { echo "<li>Arquivo do blog"; echo '</li>'; } elseif (is_search()) { echo "<li>Resultados da pesquisa"; echo '</li>'; } echo '</ul>'; }
/** * Is Tree */ function is_tree($pid) { global $post; $ancestors = get_post_ancestors($pid); $children = get_pages('child_of=' . $pid); if (empty($ancestors) && empty($children)) { return false; } return true; }
function get_top_ancestor_id() { global $post; if ($post->post_parent) { //get the array of parents posts ofthe curent post $ancestors = array_reverse(get_post_ancestors($post->ID)); return $ancestors[0]; } return $post->ID; }
function Grafik_Shortcode_AncestorLink_Callback($atts) { global $GRAFIK_ID; $a = shortcode_atts(array('level' => 0, 'class' => '', 'id' => ''), $atts); $r_ancestors = get_post_ancestors($GRAFIK_ID); array_unshift($r_ancestors, $GRAFIK_ID); $ancestors = array_reverse($r_ancestors); $level_id = $ancestors[min(count($ancestors), $a['level'])]; return '<a href="' . get_permalink($level_id) . '" class="theme-ancestorlink' . ($level_id == $GRAFIK_ID ? ' active' : null) . (empty($a['class']) ? null : ' ' . $a['class']) . '"' . (empty($a['id']) ? null : ' id="' . $a['id'] . '"') . '>' . get_the_title($level_id) . '</a>'; }
function check_parent_conference($post_id) { global $post; $current_post_id = $post->ID; echo var_trace('current_post_id: ' . $current_post_id, $TRACE_PREFIX, $TRACE_ENABLED); if ($current_post_id == $post_id or in_array($post_id, get_post_ancestors($current_post_id))) { return true; } else { return false; } }
function get_top_ancestor_id() { global $post; if ($post->post_parent) { // current page has parent $ancestors = array_reverse(get_post_ancestors($post->ID)); return $ancestors[0]; // first = direct parent } return $post->ID; }
function is_tree($pid) { global $post; $ancestors = get_post_ancestors($post->{$pid}); $root = count($ancestors) - 1; $parent = $ancestors[$root]; if (is_page() && (is_page($pid) || $post->post_parent == $pid || in_array($pid, $ancestors))) { return true; } else { return false; } }
function get_top_parent_page_id($id, $offset = FALSE) { $parents = get_post_ancestors($id); if (!$offset) { $offset = 1; } $index = count($parents) - $offset; if ($index < 0) { $index = count($parents) - 1; } return $parents ? $parents[$index] : $id; }