示例#1
0
 /**
  * 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;
 }
 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));
 }
 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;
 }
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);
    }
}
示例#5
0
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;
}
 /**
  * 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.
         }
     }
 }
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');
    }
}
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;
}
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;
}
示例#10
0
/**
 * 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;
}
示例#11
0
/**
 * 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]&amp;feed=$matches[2]';
                $rules['(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&amp;feed=$matches[2]';
                $rules['(' . $slug . ')(/page/(\\d+))?/?$'] = 'index.php?category_name=$matches[1]&amp;paged=$matches[3]';
            }
        }
    }
    return $rules;
}
示例#12
0
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, ' &raquo; ') . $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> &raquo; ' . $titles . '	</div>' . '</div>';
}
示例#13
0
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 = " &#92; ";
        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('');
    }
}
示例#14
0
/**
 * 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;
}
 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);
 }
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>';
}
示例#17
0
文件: breadcrumbs.php 项目: soska/dte
 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;
 }
 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;
 }
示例#19
0
function the_crumbs()
{
    echo '<nav class="crumbs">现在位置: ';
    echo '<a title="返回首页" href="';
    echo get_settings('home');
    echo '">';
    echo '首页';
    echo "</a>";
    if (is_category()) {
        echo ' &gt; ';
        echo get_category_parents(get_query_var('cat'), true, ' &gt; ');
        echo ' 文章 ';
    }
    if (is_single()) {
        echo ' &gt; ';
        echo the_category(' &gt; ', 'multiple');
        echo ' &gt; ';
        echo ' 正文 ';
    }
    if (is_page()) {
        echo ' &gt; ';
        echo the_title();
    } elseif (is_tag()) {
        echo ' &gt; ';
        single_tag_title();
        echo ' &gt; 文章 ';
    } elseif (is_day()) {
        echo ' &gt; ';
        echo "发表于";
        the_time('Y年m月d日');
        echo '的文章';
    } elseif (is_month()) {
        echo ' &gt; ';
        echo "发表于";
        the_time('Y年m月');
        echo '的文章';
    } elseif (is_year()) {
        echo ' &gt; ';
        echo "发表于";
        the_time('Y年');
        echo '的文章';
    } elseif (is_author()) {
        echo ' &gt; ';
        echo wp_title('');
        echo '发表的文章';
    } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {
        echo "Blog Archives";
        echo '';
    } elseif (is_search()) {
        echo ' &gt; ';
        echo "搜索结果";
        echo '';
    }
    echo '</nav>';
}
 /**
  * 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;
 }
 /**
  * Enables a custom or no category base, if the site wants to use one that's not the WP.com default (/category/)
  *
  * Usage:
  *     wpcom_vip_load_category_base( '' );
  *     wpcom_vip_load_category_base( 'section' );
  *
  * @link http://vip.wordpress.com/documentation/change-your-pretty-permalinks-or-add-custom-rewrite-rules/ Change Your Pretty Permalinks
  * @param string $new_category_base New category base prefix
  */
 function wpcom_vip_load_category_base($new_category_base)
 {
     define('WPCOM_VIP_CUSTOM_CATEGORY_BASE', true);
     global $wpcom_vip_category_base;
     $wpcom_vip_category_base = $new_category_base;
     add_filter('pre_option_category_base', '_wpcom_vip_filter_category_base', 99);
     // needs to be higher priority so we don't conflict with the WP.com filter
     // For empty category base, remove the '/category/' from the base, but include the parent category if it's a child
     if ('' === $new_category_base) {
         add_filter('category_link', function ($link, $term_id) {
             return '/' . get_category_parents($term_id, false, '/', true);
         }, 9, 2);
     }
 }
function get_permalink($id = 0, $leavename = false)
{
    $rewritecode = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', $leavename ? '' : '%postname%', '%post_id%', '%category%', '%author%', $leavename ? '' : '%pagename%');
    $post =& get_post($id);
    if (empty($post->ID)) {
        return FALSE;
    }
    if ($post->post_type == 'page') {
        return get_page_link($post->ID, $leavename);
    } elseif ($post->post_type == 'attachment') {
        return get_attachment_link($post->ID);
    }
    $permalink = get_option('permalink_structure');
    if ('' != $permalink && !in_array($post->post_status, array('draft', 'pending'))) {
        $unixtime = strtotime($post->post_date);
        $category = '';
        if (strpos($permalink, '%category%') !== false) {
            $cats = get_the_category($post->ID);
            if ($cats) {
                usort($cats, '_usort_terms_by_ID');
            }
            // order by ID
            $category = $cats[0]->slug;
            if ($parent = $cats[0]->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;
            }
        }
        $author = '';
        if (strpos($permalink, '%author%') !== false) {
            $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);
        $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
        $permalink = user_trailingslashit($permalink, 'single');
        return apply_filters('post_link', $permalink, $post);
    } else {
        // if they're not using the fancy permalink option
        $permalink = get_option('home') . '/?p=' . $post->ID;
        return apply_filters('post_link', $permalink, $post);
    }
}
示例#23
0
function get_breadcrumbs()
{
    global $wp_query;
    $breadcrumbs = "";
    if (!is_home()) {
        $breadcrumbs .= '<li><a title="' . get_bloginfo('name') . '" href="' . get_settings('home') . '">' . get_bloginfo('name') . '</a></li>';
        if (is_category()) {
            $catTitle = single_cat_title("", false);
            $cat = get_cat_ID($catTitle);
            $breadcrumbs .= "<li>" . get_category_parents($cat, true, "") . "</li>";
        } elseif (is_archive() && !is_category()) {
            $y = get_query_var('year');
            $m = get_query_var('monthnum');
            if (is_year()) {
                $breadcrumbs .= "<li>" . $y . "年</li>";
            }
            if (is_month()) {
                $breadcrumbs .= '<li><a title="' . $y . '年" href="' . get_year_link($y) . '">' . $y . '年</a></li>';
                $breadcrumbs .= "<li>" . $m . "月</li>";
            }
        } elseif (is_search()) {
            $breadcrumbs .= "<li>Search Results</li>";
        } elseif (is_404()) {
            $breadcrumbs .= "<li>404 Not Found</li>";
        } elseif (is_single()) {
            $category = get_the_category();
            $category_id = get_cat_ID($category[0]->cat_name);
            $breadcrumbs .= '<li>' . get_category_parents($category_id, true, "") . "</li>";
            $breadcrumbs .= '<li>' . get_the_title(get_query_var('p')) . "</li>";
        } elseif (is_page()) {
            $post = $wp_query->get_queried_object();
            if ($post->post_parent == 0) {
                $breadcrumbs .= "<li>" . the_title('', '', false) . "</li>";
            } else {
                $title = the_title('', '', false);
                $ancestors = array_reverse(get_post_ancestors($post->ID));
                array_push($ancestors, $post->ID);
                foreach ($ancestors as $ancestor) {
                    if ($ancestor != end($ancestors)) {
                        $breadcrumbs .= '<li><a href="' . get_permalink($ancestor) . '">' . strip_tags(apply_filters('single_post_title', get_the_title($ancestor))) . '</a></li>';
                    } else {
                        $breadcrumbs .= '<li>' . strip_tags(apply_filters('single_post_title', get_the_title($ancestor))) . '</li>';
                    }
                }
            }
        }
    }
    return $breadcrumbs;
}
示例#24
0
function wfm_title($title)
{
    $title = null;
    $sep = ' - ';
    $site = get_bloginfo('name');
    //главная страница
    if (is_home() || is_front_page()) {
        $title = array($site);
    } elseif (is_page()) {
        $title = array(get_the_title(), $site);
    } elseif (is_tag()) {
        $title = array(single_tag_title('Метка: ', false), $site);
    } elseif (is_search()) {
        $title = array('Результаты поиска по запросу:' . get_search_query());
    } elseif (is_category()) {
        //id категории
        $cat_id = get_query_var('cat');
        //данные категории
        if ($cat->parent) {
            //если есть родительская категория
            $categories = rtrim(get_category_parents($cat_id, false, $sep), $sep);
            $categories = explode($sep, $categories);
            $categories[] = $site;
            $categories = array_reverse($categories);
            $title[] = $site;
        } else {
            //если это самостоятельная категория
            $title = array($cat->name, $site);
        }
    }
    // записи
    if (is_single()) {
        //массив данных о категориях
        $category = get_the_category();
        //ID категории
        $cat_id = $category[0]->cat_ID;
        //родительские категории
        $categories = rtrim(get_category_parents($cat_id, false, $sep), $sep);
        $categories = explode($sep, $categories);
        $categories = get_the_title();
        $categories = array_reverse($categories);
        $title[] = $site;
    } elseif (is_archive()) {
        $title = array('Архив за:' . get_the_time("F Y"), $site);
    }
    $title = implode($sep, $title);
    return $title;
}
示例#25
0
文件: functions.php 项目: voituk/Misc
 /**
  * Check if current post relate to the specified category or any level parent category
  * @param string|array $slug_list - category slug or slugs array
  * @usage Inside The_Loop
  */
 function is_in_toplevel_category($slug_list)
 {
     global $post;
     $slug_list = (array) $slug_list;
     //print_r($post);
     foreach (get_the_category() as $cat) {
         if (in_array($cat->slug, $slug_list)) {
             return true;
         }
         foreach (explode('||', get_category_parents($cat, false, '||', true)) as $s) {
             if (in_array($s, $slug_list)) {
                 return true;
             }
         }
     }
     return false;
 }
function breadcrumb()
{
    global $post;
    $postcate = get_the_category($post->post_id);
    $cat_bread = get_category_parents($postcate[0]->term_id, TRUE);
    ?>
  <ol>
    <li><a href="<?php 
    echo home_url('/');
    ?>
">ホーム</a></li>
    <li><?php 
    echo $cat_bread;
    ?>
</li>
  </ol>
<?php 
}
示例#27
0
 function swift_get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE)
 {
     $chain = '';
     $parent =& get_category($id);
     if (is_wp_error($parent)) {
         return $parent;
     }
     if ($nicename) {
         $name = $parent->slug;
     } else {
         $name = $parent->cat_name;
     }
     if ($parent->parent && $parent->parent != $parent->term_id) {
         $chain .= get_category_parents($parent->parent, true, $separator, $nicename);
     }
     $chain .= $name;
     return $chain;
 }
示例#28
0
function breadcrumb_inject_post_category($parent, $item)
{
    if (is_singular('post') && $parent instanceof Breadcrumb_Item_Archive && $item instanceof Breadcrumb_Item_Singular) {
        $level = 0;
        $cat = null;
        foreach (wp_get_post_categories($item->item->ID) as $cat_id) {
            $cat_parents = get_category_parents($cat_id, false, '[SEPARATOR]');
            $cat_level = count(explode('[SEPARATOR]', $cat_parents)) - 1;
            if ($cat_level > $level) {
                $level = $cat_level;
                $cat = $cat_id;
            }
        }
        if ($cat) {
            $parent = new Breadcrumb_Item_Taxonomy(get_category($cat));
        }
    }
    return $parent;
}
 /**
  * Breadcrumbs data
  *
  * @return array
  */
 public static function breadcrumbs_data()
 {
     global $post, $author;
     $qo = get_queried_object();
     $data = array('separator' => '&gt;', 'breadcrums_id' => 'breadcrumbs', 'breadcrums_class' => 'breadcrumbs', 'home_title' => 'Homepage', 'custom_taxonomy' => 'product_cat', 'post_type' => get_post_type(), 'post_type_object' => get_post_type_object(get_post_type()), 'post_type_archive' => get_post_type_archive_link(get_post_type()), 'category' => get_the_category(), 'post' => $post);
     if (null != $qo) {
         $data['custom_tax_name'] = $qo->name;
     }
     if (!empty($data['category'])) {
         $values = array_values($data['category']);
         $data['last_category'] = end($values);
         $data['get_cat_parents'] = rtrim(get_category_parents($data['last_category']->term_id, true, ','), ',');
         $data['cat_parents'] = explode(',', $data['get_cat_parents']);
     }
     $data['taxonomy_exists'] = taxonomy_exists($data['custom_taxonomy']);
     if (empty($data['last_category']) && !empty($data['custom_taxonomy']) && $data['taxonomy_exists']) {
         $data['taxonomy_terms'] = get_the_terms($post->ID, $data['custom_taxonomy']);
         $data['cat_id'] = $data['taxonomy_terms'][0]->term_id;
         $data['cat_nicename'] = $data['taxonomy_terms'][0]->slug;
         $data['cat_link'] = get_term_link($data['taxonomy_terms'][0]->term_id, $data['custom_taxonomy']);
         $data['cat_name'] = $data['taxonomy_terms'][0]->name;
     }
     if (null != $post) {
         if ($post->post_parent) {
             $data['anc'] = get_post_ancestors($post->ID);
             $data['anc'] = array_reverse($data['anc']);
         }
     }
     if (is_tag()) {
         $data['term_id'] = get_query_var('tag_id');
         $data['taxonomy'] = 'post_tag';
         $data['args'] = 'include=' . $term_id;
         $data['terms'] = get_terms($taxonomy, $args);
         $data['get_term_id'] = $data['terms'][0]->term_id;
         $data['get_term_slug'] = $data['terms'][0]->slug;
         $data['get_term_name'] = $data['terms'][0]->name;
     }
     if (is_author()) {
         $data['userdata'] = get_userdata($author);
     }
     return $data;
 }
示例#30
0
function get_generations($id, $catfather_array = array())
{
    // $catfather_array eg: array ('events' => 12, 'voices' => 18) - these are 'category_nicename' aka 'slug'
    // $catfather_array associates categories with pages - not necessarily at top level
    $lowest_page_id = $id;
    // but if this a post with a catfather, use the catfather instead
    if (is_single($id) && !empty($catfather_array)) {
        // v6.49  != '') {
        $cat = get_the_category($id);
        // array of objects, one for each category assigned - but only $cat[0] is used
        d('$cat', $cat);
        if (count($cat) > 0) {
            // v6.50 changed to work with sub-categories - but not if more than 1 box ticked
            $parentCatList = get_category_parents($cat[0]->cat_ID, false, ',', true);
            //param 4 = Whether to use catslug (=nicename) for display.
            $parentCatListArray = explode(",", $parentCatList);
            // array of catslugs
            $top_parent_cat = $parentCatListArray[0];
            d('$top_parent_cat', $top_parent_cat);
            foreach ($catfather_array as $catslug => $cf_id) {
                if ($catslug == $top_parent_cat) {
                    // AND category inheritance hasn't been turned off?
                    $lowest_page_id = $cf_id;
                }
            }
        }
    }
    d('$lowest_page_id', $lowest_page_id);
    // ie: we're now starting either from the current ID or the $catfather ID, neither of which is necessarily at top level
    $generations = get_post_ancestors($lowest_page_id);
    // parent = first, godfather = last
    array_unshift($generations, $lowest_page_id);
    // $lowest_page_id followed by all ancestors
    if ($lowest_page_id != $id) {
        // ie: $id is a post with a catfather of $lowest_page_id
        array_unshift($generations, $id);
        // can't get rid of this without breaking current/inherited stuff
    }
    d('$generations', $generations);
    return $generations;
}