本文整理汇总了PHP中get_post_ancestors函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_ancestors函数的具体用法?PHP get_post_ancestors怎么用?PHP get_post_ancestors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_post_ancestors函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: the_breadcrumb
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>';
}
}
}
}
示例2: ski_bg_class
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";
}
}
示例3: getpp_replace_hierarchicals
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;
}
示例4: tool_private_is_private_post
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;
}
示例5: bb_param_pages
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;
}
示例6: genesis_page_checklist
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;
}
示例7: aiga_nebraska_body_class
/**
* 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;
}
示例8: get_page_parent_title
/**
* 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;
}
示例9: getAncestorsAttribute
/**
* 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);
}
示例10: rooftop_add_content_hierarchy
/**
* 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;
}
示例11: shortcode_handler
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);
}
示例12: is_page_branch
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;
}
示例13: occasions_breadcrumbs
/**
* 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>';
}
}
示例14: widget
/**
* 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;
}
示例15: jetpack_breadcrumbs
/**
* 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>';
}