本文整理汇总了PHP中get_post_ancestors函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_ancestors函数的具体用法?PHP get_post_ancestors怎么用?PHP get_post_ancestors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_post_ancestors函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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>';
}
}
}
}
开发者ID:plusinterativa,项目名称:clientes,代码行数:29,代码来源:functions.php
示例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";
}
}
开发者ID:utah-marketing-communications,项目名称:umc_skitheme,代码行数:35,代码来源:body_bg_class.php
示例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;
}
开发者ID:bristweb,项目名称:codexcodes,代码行数:7,代码来源:index.php
示例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;
}
开发者ID:studio-montana,项目名称:custom,代码行数:25,代码来源:private.php
示例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;
}
开发者ID:sebjon-bytbil,项目名称:BB.CMS,代码行数:25,代码来源:pages.php
示例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;
}
开发者ID:elderxavier,项目名称:ALLAN-JUNIOR-IAN,代码行数:26,代码来源:admin.php
示例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;
}
开发者ID:aiganebraska,项目名称:AIGA-Nebraska,代码行数:31,代码来源:etc_utils.php
示例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;
}
开发者ID:softcatala,项目名称:wp-softcatala,代码行数:11,代码来源:post_types_functions.php
示例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);
}
开发者ID:hrslash,项目名称:luminous,代码行数:14,代码来源:HierarchicalEntity.php
示例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;
}
开发者ID:rooftopcms,项目名称:rooftop-content-hierarchy,代码行数:55,代码来源:rooftop-content-hierarchy.php
示例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);
}
开发者ID:ssnepenthe,项目名称:hestia,代码行数:30,代码来源:Ancestors.php
示例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;
}
开发者ID:Teplitsa,项目名称:giger,代码行数:26,代码来源:template-tags.php
示例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>';
}
}
开发者ID:heathervreeland,项目名称:Mediakit-Occasions-Online,代码行数:31,代码来源:breadcrumb.php
示例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;
}
开发者ID:markbiek,项目名称:Silencio,代码行数:36,代码来源:SilencioChildrenPages.php
示例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>';
}
开发者ID:kanei,项目名称:vantuch.cz,代码行数:41,代码来源:site-breadcrumbs.php
示例16: test_get_post_ancestors_with_falsey_values
/**
* @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));
}
}
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:10,代码来源:objects.php
示例17: the_breadcrumbs
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: ";
}
}
开发者ID:psutak,项目名称:iatheme,代码行数:59,代码来源:functions.php
示例18: get_top_parent_id
function get_top_parent_id()
{
if ($post->post_parent) {
$ancestor = array_reverse(get_post_ancestors($post->ID));
return $ancestor[0];
}
return $post->ID;
}
开发者ID:rkking,项目名称:Winter-15,代码行数:8,代码来源:functions.php
示例19: get_the_breadcrumb
/**
* [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>';
}
开发者ID:nemesiscodex,项目名称:Semantic-UI-WordPress,代码行数:63,代码来源:custom-functions.php
示例20: breadcrumbs
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>';
}
开发者ID:andresmatasuarez,项目名称:jedbangers-web,代码行数:57,代码来源:functions.php
注:本文中的get_post_ancestors函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论