欢迎光临Software MyZone,有问题可留言或到站点论坛发帖,争取第一时间帮忙解决 || 站点论坛:火龙论坛 || 淘宝小店:应小心的易淘屋 【欢迎大家提建设性意见】

WordPress设置站点导航

方法一:直接在相关页面添加代码即可实现导航

在single.php、archive.php等添加以下代码:

 <div class="mbx-dh">
 当前位置:<a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a> &raquo;
 <?php
 if( is_single() ){
 $categorys = get_the_category();
 $category = $categorys[0];
 echo( get_category_parents($category->term_id,true,' &raquo; ') );
 the_title();
 } elseif ( is_page() ){
 the_title();
 } elseif ( is_category() ){
 single_cat_title();
 } elseif ( is_tag() ){
 single_tag_title();
 } elseif ( is_day() ){
 the_time('Y年Fj日');
 } elseif ( is_month() ){
 the_time('Y年F');
 } elseif ( is_year() ){
 the_time('Y年');
 } elseif ( is_search() ){
 echo $s.' 的搜索结果';
 }
 ?>
 </div>

方法二:通过 functions.php 调用实现导航效果

function dimox_breadcrumbs() {

  $delimiter = '»';
  $name = 'Home'; //text for the 'Home' link
  $currentBefore = '<span>';
 $currentAfter = '</span>';

  if ( !is_home() && !is_front_page() || is_paged() ) {

    echo '</pre>
<div id="crumbs">
';

 global $post;
 $home = get_bloginfo('url');
 echo '<a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' ';

 if ( is_category() ) {
 global $wp_query;
 $cat_obj = $wp_query->get_queried_object();
 $thisCat = $cat_obj->term_id;
 $thisCat = get_category($thisCat);
 $parentCat = get_category($thisCat->parent);
 if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
 echo $currentBefore . 'Archive by category '';
 single_cat_title();
 echo ''' . $currentAfter;

 } elseif ( is_day() ) {
 echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
 echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
 echo $currentBefore . get_the_time('d') . $currentAfter;

 } elseif ( is_month() ) {
 echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
 echo $currentBefore . get_the_time('F') . $currentAfter;

 } elseif ( is_year() ) {
 echo $currentBefore . get_the_time('Y') . $currentAfter;

 } elseif ( is_single() ) {
 $cat = get_the_category(); $cat = $cat[0];
 echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
 echo $currentBefore;
 the_title();
 echo $currentAfter;

 } elseif ( is_page() && !$post->post_parent ) {
 echo $currentBefore;
 the_title();
 echo $currentAfter;

 } elseif ( is_page() && $post->post_parent ) {
 $parent_id = $post->post_parent;
 $breadcrumbs = array();
 while ($parent_id) {
 $page = get_page($parent_id);
 $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
 $parent_id = $page->post_parent;
 }
 $breadcrumbs = array_reverse($breadcrumbs);
 foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
 echo $currentBefore;
 the_title();
 echo $currentAfter;

 } elseif ( is_search() ) {
 echo $currentBefore . 'Search results for '' . get_search_query() . ''' . $currentAfter;

 } elseif ( is_tag() ) {
 echo $currentBefore . 'Posts tagged '';
 single_tag_title();
 echo ''' . $currentAfter;

 } elseif ( is_author() ) {
 global $author;
 $userdata = get_userdata($author);
 echo $currentBefore . 'Articles posted by ' . $userdata->display_name . $currentAfter;

 } elseif ( is_404() ) {
 echo $currentBefore . 'Error 404' . $currentAfter;
 }

 if ( get_query_var('paged') ) {
 if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
 echo __('Page') . ' ' . get_query_var('paged');
 if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
 }

 echo '</div>
<pre>
';

  }
}

最后在适当的地方(如方法一中提到的几个文件)添加以下代码调用:

<div class="mbx-dh">
<?php if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); ?>
</div>

摘自(有改动):http://www.yzznl.cn/archives/add-breadcrumbs.html#comment-51119