本文整理汇总了PHP中get_category_parents函数的典型用法代码示例。如果您正苦于以下问题:PHP get_category_parents函数的具体用法?PHP get_category_parents怎么用?PHP get_category_parents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_category_parents函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: category_rewrite_rules
/**
* This function taken and only slightly adapted from WP No Category Base plugin by Saurabh Gupta
*/
function category_rewrite_rules($rewrite)
{
global $wp_rewrite;
$category_rewrite = array();
$categories = get_categories(array('hide_empty' => false));
$blog_prefix = '';
if (function_exists('is_multisite') && is_multisite() && !is_subdomain_install() && is_main_site()) {
$blog_prefix = 'blog/';
}
foreach ($categories as $category) {
$category_nicename = $category->slug;
if ($category->parent == $category->cat_ID) {
// recursive recursion
$category->parent = 0;
} elseif ($category->parent != 0) {
$category_nicename = get_category_parents($category->parent, false, '/', true) . $category_nicename;
}
$category_rewrite[$blog_prefix . '(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$category_rewrite[$blog_prefix . '(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
$category_rewrite[$blog_prefix . '(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]';
}
// Redirect support from Old Category Base
$old_base = $wp_rewrite->get_category_permastruct();
$old_base = str_replace('%category%', '(.+)', $old_base);
$old_base = trim($old_base, '/');
$category_rewrite[$old_base . '$'] = 'index.php?wpseo_category_redirect=$matches[1]';
return $category_rewrite;
}
开发者ID:kitfrench,项目名称:Futurestep,代码行数:31,代码来源:class-rewrite.php
示例2: test_visited
public function test_visited()
{
$c3 = self::factory()->category->create_and_get(array('parent' => $this->c2->term_id));
$c4 = self::factory()->category->create_and_get(array('parent' => $c3->term_id));
$expected = $this->c1->name . '/' . $this->c2->name . '/' . $c4->name . '/';
$found = get_category_parents($this->c2->term_id, false, '/', false, array($c3->term_id));
}
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:7,代码来源:getCategoryParents.php
示例3: parseLink
function parseLink($permalink, $post)
{
if ('' != $permalink && !in_array($post->post_status, array('draft', 'pending'))) {
$category = '';
if (strpos($permalink, '%scategory%') !== false) {
$cat = null;
$category_permalink = get_post_meta($post->ID, '_category_permalink', true);
if ($category_permalink) {
$cat = get_category($category_permalink);
}
if (!$cat) {
$cats = get_the_category($post->ID);
usort($cats, '_usort_terms_by_ID');
// order by ID
$cat = $cats[0];
}
$category = $cat->slug;
if ($parent = $cat->parent) {
$category = get_category_parents($parent, false, '/', true) . $category;
}
// show default category in permalinks, without
// having to assign it explicitly
if (empty($category)) {
$default_category = get_category(get_option('default_category'));
$category = is_wp_error($default_category) ? '' : $default_category->slug;
}
}
$p = str_replace('%scategory%', $category, $permalink);
return $p;
}
return $permalink;
}
开发者ID:VitaliyProdan,项目名称:wp_shop,代码行数:32,代码来源:scategory_permalink.php
示例4: get_permalink
function get_permalink($id = 0)
{
$rewritecode = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%postname%', '%post_id%', '%category%', '%author%', '%pagename%');
$post =& get_post($id);
if ($post->post_status == 'static') {
return get_page_link($post->ID);
} elseif ($post->post_status == 'attachment') {
return get_attachment_link($post->ID);
}
$permalink = get_settings('permalink_structure');
if ('' != $permalink && 'draft' != $post->post_status) {
$unixtime = strtotime($post->post_date);
$category = '';
if (strstr($permalink, '%category%')) {
$cats = get_the_category($post->ID);
$category = $cats[0]->category_nicename;
if ($parent = $cats[0]->category_parent) {
$category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
}
}
$authordata = get_userdata($post->post_author);
$author = $authordata->user_nicename;
$date = explode(" ", date('Y m d H i s', $unixtime));
$rewritereplace = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->post_name, $post->ID, $category, $author, $post->post_name);
return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $post);
} else {
// if they're not using the fancy permalink option
$permalink = get_settings('home') . '/?p=' . $post->ID;
return apply_filters('post_link', $permalink, $post);
}
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:31,代码来源:template-functions-links.php
示例5: remove_category_url_rewrite_rules
function remove_category_url_rewrite_rules($category_rewrite)
{
$category_rewrite = array();
if (class_exists('Sitepress')) {
global $sitepress;
remove_filter('terms_clauses', array($sitepress, 'terms_clauses'));
$categories = get_categories(array('hide_empty' => false));
add_filter('terms_clauses', array($sitepress, 'terms_clauses'));
} else {
$categories = get_categories(array('hide_empty' => false));
}
foreach ($categories as $category) {
$category_nicename = $category->slug;
if ($category->parent == $category->cat_ID) {
$category->parent = 0;
} elseif ($category->parent != 0) {
$category_nicename = get_category_parents($category->parent, false, '/', true) . $category_nicename;
}
$category_rewrite['(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]';
}
global $wp_rewrite;
$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
$old_category_base = trim($old_category_base, '/');
$category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]';
return $category_rewrite;
}
开发者ID:surperone,项目名称:Tinection,代码行数:28,代码来源:no_category_base.php
示例6: smittenkitchen_primary_category
/**
* Prints HTML with meta information for the categories, tags and comments.
*/
function smittenkitchen_primary_category()
{
if ('post' == get_post_type()) {
$categories = get_the_category(get_the_ID());
// For each category, derive a list of top-level parent categories.
$parent_categories = array();
foreach ($categories as $category) {
if (0 === $category->category_parent) {
$top_level_parent = $category->name;
} else {
// Get the top-level parent.
$all_parents = get_category_parents($category->term_id, false, '&&&');
$all_parents = explode('&&&', $all_parents);
$top_level_parent = $all_parents[0];
}
// Add category to our array.
if (!in_array($top_level_parent, $parent_categories)) {
$parent_categories[] = $top_level_parent;
}
}
// Join strings together!
$parent_category_string = implode(', ', $parent_categories);
if ($parent_category_string && smittenkitchen_categorized_blog()) {
printf('<span class="smittenkitchen-primary-category">' . esc_html__('%1$s', 'smittenkitchen') . '</span>', $parent_category_string);
// WPCS: XSS OK.
}
}
}
开发者ID:a8cteam51,项目名称:smittenkitchen,代码行数:31,代码来源:template-tags.php
示例7: bavota_breadcrumbs
function bavota_breadcrumbs()
{
if (!is_front_page()) {
echo '<a href="' . home_url('/') . 'blog">Blog</a><span class="divider"> <i class="icon-angle-right"></i> </span>';
}
if (is_category() || is_single()) {
$category = get_the_category();
$ID = $category[0]->cat_ID;
// echo get_category_parents($ID, TRUE, ' ', FALSE ); // was causing errors in the error_log
echo is_wp_error($cat_parents = get_category_parents($ID, TRUE, ' ', FALSE)) ? '' : $cat_parents;
}
$mytitle = get_the_title();
if (strlen($mytitle) > 22) {
$mytitle = substr($mytitle, 0, 38) . "...";
}
if (is_single() || is_page()) {
echo ' <span class="divider"> <i class="icon-angle-right"></i> </span> ';
echo $mytitle;
}
if (is_tag()) {
echo "Tag: " . single_tag_title('', FALSE);
}
if (is_404()) {
echo "404 - Page not Found";
}
if (is_search()) {
echo "Search";
}
if (is_year()) {
echo get_the_time('Y');
}
}
开发者ID:jonbrown21,项目名称:JBD-Wordpress-Theme,代码行数:32,代码来源:functions.php
示例8: no_category_base_rewrite_rules
function no_category_base_rewrite_rules($category_rewrite)
{
//var_dump($category_rewrite); // For Debugging
$category_rewrite = array();
$categories = get_categories(array('hide_empty' => false));
foreach ($categories as $category) {
$category_nicename = $category->slug;
if ($category->parent == $category->cat_ID) {
// recursive recursion
$category->parent = 0;
} elseif ($category->parent != 0) {
$category_nicename = get_category_parents($category->parent, false, '/', true) . $category_nicename;
}
$category_rewrite['(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]';
}
// Redirect support from Old Category Base
global $wp_rewrite;
$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
$old_category_base = trim($old_category_base, '/');
$category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]';
//var_dump($category_rewrite); // For Debugging
return $category_rewrite;
}
开发者ID:howardlei82,项目名称:IGSM-Website,代码行数:25,代码来源:no-category-base.php
示例9: no_category_base_rewrite_rules
function no_category_base_rewrite_rules($category_rewrite) {
//print_r($category_rewrite); // For Debugging
$category_rewrite=array();
$categories=get_categories(array('hide_empty'=>false));
foreach($categories as $category) {
$category_nicename = $category->slug;
if ( $category->parent == $category->cat_ID ) // recursive recursion
$category->parent = 0;
elseif ($category->parent != 0 )
$category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename;
$category_rewrite['('.$category_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$category_rewrite['('.$category_nicename.')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
$category_rewrite['('.$category_nicename.')/?$'] = 'index.php?category_name=$matches[1]';
}
// Redirect support from Old Category Base
global $wp_rewrite;
$old_base = $wp_rewrite->get_category_permastruct();
$old_base = str_replace( '%category%', '(.+)', $old_base );
$old_base = trim($old_base, '/');
$category_rewrite[$old_base.'$'] = 'index.php?category_redirect=$matches[1]';
//print_r($category_rewrite); // For Debugging
return $category_rewrite;
}
开发者ID:nerdfiles,项目名称:sideshowtramps.com,代码行数:25,代码来源:no-category-base.php
示例10: remove_category_url_rewrite_rules
/**
* Adds our custom category rewrite rules.
*
* @param array $category_rewrite Category rewrite rules.
*
* @return array
*/
function remove_category_url_rewrite_rules($category_rewrite)
{
global $wp_rewrite;
$category_rewrite = array();
/* WPML is present: temporary disable terms_clauses filter to get all categories for rewrite */
if (class_exists('Sitepress')) {
global $sitepress;
remove_filter('terms_clauses', array($sitepress, 'terms_clauses'));
$categories = get_categories(array('hide_empty' => false, '_icl_show_all_langs' => true));
add_filter('terms_clauses', array($sitepress, 'terms_clauses'));
} else {
$categories = get_categories(array('hide_empty' => false));
}
foreach ($categories as $category) {
$category_nicename = $category->slug;
if ($category->parent == $category->cat_ID) {
$category->parent = 0;
} elseif (0 != $category->parent) {
$category_nicename = get_category_parents($category->parent, false, '/', true) . $category_nicename;
}
$category_rewrite['(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]';
}
// Redirect support from Old Category Base
$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
$old_category_base = trim($old_category_base, '/');
$category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]';
return $category_rewrite;
}
开发者ID:jolupeza,项目名称:informal,代码行数:37,代码来源:remove-category-url.php
示例11: smittenkitchen_filter_category_rewrite_rules
/**
* Remove the 'category' base from category URIs.
*/
function smittenkitchen_filter_category_rewrite_rules($rules)
{
$categories = get_categories(array('hide_empty' => false));
if (is_array($categories) && !empty($categories)) {
$slugs = array();
foreach ($categories as $category) {
if (is_object($category) && !is_wp_error($category)) {
if (0 == $category->category_parent) {
$slugs[] = $category->slug;
} else {
$slugs[] = trim(get_category_parents($category->term_id, false, '/', true), '/');
}
}
}
if (!empty($slugs)) {
$rules = array();
foreach ($slugs as $slug) {
$rules['(' . $slug . ')/feed/(feed|rdf|rss|rss2|atom)?/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules['(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules['(' . $slug . ')(/page/(\\d+))?/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[3]';
}
}
}
return $rules;
}
开发者ID:a8cteam51,项目名称:smittenkitchen,代码行数:28,代码来源:vip-functions.php
示例12: crumb
function crumb()
{
if (is_attachment()) {
$titles = $title = '附件';
} elseif (is_single()) {
$categorys = get_the_category();
$category = $categorys[0];
$title = get_the_title();
$titles = get_category_parents($category->term_id, true, ' » ') . $title;
} elseif (is_page()) {
$titles = $title = get_the_title();
} elseif (is_category()) {
$titles = $title = single_cat_title('', false);
} elseif (is_tag()) {
$titles = $title = single_tag_title('', false);
} elseif (is_day()) {
$titles = $title = get_the_time('Y年Fj日');
} elseif (is_month()) {
$titles = $title = get_the_time('Y年F');
} elseif (is_year()) {
$titles = $title = get_the_time('Y年');
} elseif (is_search()) {
global $s;
$titles = $title = $s . ' 的搜索结果';
} else {
$titles = $title = '';
}
echo '<div class="crumb">' . ' <strong style="display:inline;">' . $title . '</strong>' . ' <div class="nav_crumb">' . ' <a href="' . get_bloginfo('url') . '" title="' . get_bloginfo('name') . '">HOME</a> » ' . $titles . ' </div>' . '</div>';
}
开发者ID:netwolf103,项目名称:dvpoo,代码行数:29,代码来源:crumb.php
示例13: rt_breadcrumb
function rt_breadcrumb($gecerli_sayfa)
{
if (is_page()) {
$ust_id = $gecerli_sayfa->post_parent;
$yeni_sorgu = get_post($ust_id);
if ($yeni_sorgu->post_parent) {
rt_breadcrumb($yeni_sorgu);
echo " \\ ";
}
echo "<a href=\"" . get_permalink($yeni_sorgu->ID) . "\" title=\"\" >" . get_the_title($yeni_sorgu->ID) . "</a>";
} elseif (is_single() || is_category() && !is_archive()) {
$ust_id = $gecerli_sayfa->post_parent;
$yeni_sorgu = get_post($ust_id);
$kategori = get_the_category($yeni_sorgu->ID);
$ID = $kategori[0]->cat_ID;
$ayrac = " \ ";
echo get_category_parents($ID, TRUE, $ayrac, FALSE);
if ($yeni_sorgu->post_parent) {
rt_breadcrumb($yeni_sorgu);
if (!is_category()) {
echo " \\ ";
}
}
if (is_single()) {
echo "<a href=\"" . get_permalink($yeni_sorgu->ID) . "\" title=\"\" >" . get_the_title($yeni_sorgu->ID) . "</a>";
}
} else {
echo wp_title('');
}
}
开发者ID:xiaoxiaoleo,项目名称:yihe,代码行数:30,代码来源:functions.php
示例14: basey_breadcrumbs
/**
* Breadcrumbs
* @return html
* @source http://yootheme.com (Warp Themes)
*/
function basey_breadcrumbs()
{
global $wp_query;
if (!is_home() && !is_front_page()) {
$output = '<ul class="zz-link-more-muted zz-text-more-muted zz-position-up uk-breadcrumb uk-hidden-small">';
$output .= '<li><a href="' . get_option('home') . '">Home</a></li>';
if (is_single()) {
$cats = get_the_category();
if ($cats) {
$cat = $cats[0];
if (is_object($cat)) {
if ($cat->parent != 0) {
$cats = explode("@@@", get_category_parents($cat->term_id, true, "@@@"));
unset($cats[count($cats) - 1]);
$output .= str_replace('<li>@@', '<li>', '<li>' . implode("</li><li>", $cats) . '</li>');
} else {
$output .= '<li><a href="' . get_category_link($cat->term_id) . '">' . $cat->name . '</a></li>';
}
}
}
}
if (is_category()) {
$cat_obj = $wp_query->get_queried_object();
$cats = explode("@@@", get_category_parents($cat_obj->term_id, TRUE, '@@@'));
unset($cats[count($cats) - 1]);
$cats[count($cats) - 1] = '@@<span>' . strip_tags($cats[count($cats) - 1]) . '</span>';
$output .= str_replace('<li>@@', '<li class="uk-active">', '<li>' . implode("</li><li>", $cats) . '</li>');
} elseif (is_tag()) {
$output .= '<li class="uk-active"><span>' . single_cat_title('', false) . '</span></li>';
} elseif (is_date()) {
$output .= '<li class="uk-active"><span>' . single_month_title(' ', false) . '</span></li>';
} elseif (is_author()) {
$user = get_user_by('login', get_the_author());
$output .= '<li class="uk-active"><span>' . $user->display_name . '</span></li>';
} elseif (is_search()) {
$output .= '<li class="uk-active"><span>' . stripslashes(strip_tags(get_search_query())) . '</span></li>';
} elseif (is_tax()) {
$taxonomy = get_taxonomy(get_query_var('taxonomy'));
$term = get_query_var('term');
$output .= '<li class="uk-active"><span>' . $taxonomy->label . ': ' . $term . '</span></li>';
} else {
if (!in_array(get_post_type(), array('post', 'page'))) {
$cpt = get_post_type_object(get_post_type());
$output .= '<li><a href="' . get_post_type_archive_link(get_post_type()) . '">' . $cpt->labels->name . '</a></li>';
}
$ancestors = get_ancestors(get_the_ID(), 'page');
for ($i = count($ancestors) - 1; $i >= 0; $i--) {
$output .= '<li><a href="' . get_page_link($ancestors[$i]) . '" title="' . get_the_title($ancestors[$i]) . '">' . get_the_title($ancestors[$i]) . '</a></li>';
}
$output .= '<li class="uk-active"><span>' . get_the_title() . '</span></li>';
}
$output .= '</ul>';
} else {
$output = '<ul class="uk-breadcrumb">';
$output .= '<li class="uk-active"><span>Home</span></li>';
$output .= '</ul>';
}
echo $output;
}
开发者ID:kokokokokokoko,项目名称:basey-theme,代码行数:64,代码来源:functions.php
示例15: test_visited_should_also_exclude_children_of_visited_categories
public function test_visited_should_also_exclude_children_of_visited_categories()
{
$c3 = self::factory()->category->create_and_get(array('parent' => $this->c2->term_id));
$c4 = self::factory()->category->create_and_get(array('parent' => $c3->term_id));
$expected = $this->c1->name . '/' . $this->c2->name . '/';
$found = get_category_parents($this->c2->term_id, false, '/', false, array($c3->term_id));
$this->assertSame($expected, $found);
}
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:8,代码来源:getCategoryParents.php
示例16: deel_breadcrumbs
function deel_breadcrumbs()
{
if (!is_single()) {
return false;
}
$categorys = get_the_category();
$category = $categorys[0];
return '<a title="返回首页" href="' . get_bloginfo('url') . '"><i class="fa fa-home"></i></a> <small>></small> ' . get_category_parents($category->term_id, true, ' <small>></small> ') . '<span class="muted">' . get_the_title() . '</span>';
}
开发者ID:dfc643,项目名称:ARCHIVE-2014-wordpress-theme-backup,代码行数:9,代码来源:functions.php
示例17: _getCategoryParentLinks
function _getCategoryParentLinks($id, &$options)
{
$links = get_category_parents($id, 1, "|");
$links = explode('|', $links);
array_pop($links);
if ($options['drop_first_category_node']) {
array_shift($links);
}
return $links;
}
开发者ID:soska,项目名称:dte,代码行数:10,代码来源:breadcrumbs.php
示例18: check_parent_name
public function check_parent_name($cat_id)
{
$curr_cat = get_category_parents($cat_id, false, '/', true);
//echo "curr_cat";
//var_dump($curr_cat);
$curr_cat = explode('/', $curr_cat);
$this->parent_catName = get_category_by_slug($curr_cat[0])->cat_name;
return get_category_by_slug($curr_cat[0])->cat_name;
//echo $this -> parent_catslug;
}
开发者ID:johan--,项目名称:UiGEN-Core,代码行数:10,代码来源:expired_template-swither.class.php
示例19: the_crumbs
function the_crumbs()
{
echo '<nav class="crumbs">现在位置: ';
echo '<a title="返回首页" href="';
echo get_settings('home');
echo '">';
echo '首页';
echo "</a>";
if (is_category()) {
echo ' > ';
echo get_category_parents(get_query_var('cat'), true, ' > ');
echo ' 文章 ';
}
if (is_single()) {
echo ' > ';
echo the_category(' > ', 'multiple');
echo ' > ';
echo ' 正文 ';
}
if (is_page()) {
echo ' > ';
echo the_title();
} elseif (is_tag()) {
echo ' > ';
single_tag_title();
echo ' > 文章 ';
} elseif (is_day()) {
echo ' > ';
echo "发表于";
the_time('Y年m月d日');
echo '的文章';
} elseif (is_month()) {
echo ' > ';
echo "发表于";
the_time('Y年m月');
echo '的文章';
} elseif (is_year()) {
echo ' > ';
echo "发表于";
the_time('Y年');
echo '的文章';
} elseif (is_author()) {
echo ' > ';
echo wp_title('');
echo '发表的文章';
} elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {
echo "Blog Archives";
echo '';
} elseif (is_search()) {
echo ' > ';
echo "搜索结果";
echo '';
}
echo '</nav>';
}
开发者ID:areszn,项目名称:wordpress,代码行数:55,代码来源:breadcrumb.php
示例20: level
/**
* Establishes the code level (zero is level one) of an existing category
*
* @author Ryan R. Bayne
* @package CSV 2 POST
* @since 8.1.3
* @version 1.1
*/
public function level($category_id)
{
$parents = get_category_parents($category_id, false, '/');
$parents = explode('/', $parents);
// remove the empty value, get_category_parents() returns string that ends with separator always
// however if they change that behaviour it would cause problems so deducting 1 should be avoided
$parents = array_diff($parents, array('', ' '));
$parents = count($parents);
// in code the levels will begin at zero, unlike UI, so deduct 1
// vale of 4 means level 5
return $parents - 1;
}
开发者ID:WebTechGlobal,项目名称:csv-2-post-1,代码行数:20,代码来源:class-categories.php
注:本文中的get_category_parents函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论