面包屑在網(wǎng)頁中經(jīng)常使用wordpress面包屑導航代碼,見下面的例子
實現(xiàn):使用自定義函數(shù)使用第三方插件
使用自定義函數(shù)(這樣的函數(shù)很多wordpress網(wǎng)站制作,寫法大同小異)

在.php文件中寫入以下代碼
//面包屑導航
function get_breadcrumbs()
{
global $wp_query;
if ( !is_home() ){
// Start the UL
echo '';
// Add the Home link
echo '- '. get_bloginfo('name') .'
';
if ( is_category() )
{
$catTitle = single_cat_title( "", false );
$cat = get_cat_ID( $catTitle );
echo "- » ". get_category_parents( $cat, TRUE, " » " ) ."
";
}
elseif ( is_archive() && !is_category() )
{
echo "- » Archives
";
}
elseif ( is_search() ) {
echo "- » Search Results
";
}
elseif ( is_404() )
{
echo "- » 404 Not Found
";
}
elseif ( is_single() )
{
$category = get_the_category();
$category_id = get_cat_ID( $category[0]->cat_name );
echo '- » '. get_category_parents( $category_id, TRUE, " » " );
echo the_title('','', FALSE) ."
";
}
elseif ( is_page() )
{
$post = $wp_query->get_queried_object();
if ( $post->post_parent == 0 ){
echo "- » ".the_title('','', FALSE)."
";
} 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) ){
echo '- » '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'
';
} else {
echo '- » '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'
';
}
}
}
}
// End the UL
echo "
";
}
}

然后將以下代碼添加到.php或page.php、.php頁面中:

使用第三方插件實現(xiàn)面包屑
我們直接在程序網(wǎng)站的后端插件中搜索“NavXT”,然后下載并激活。

在后臺設置面包屑樣式:

面包屑導航中的第一項默認顯示網(wǎng)站標題。將其更改為“主頁”
設置完成后wordpress面包屑導航代碼wordpress做網(wǎng)站,在模板中編寫如下代碼:
p>
文章來自互聯(lián)網(wǎng),侵權(quán)請聯(lián)系刪除,文章闡述觀點來自文章出處,并不代表本站觀點。
m.bjcthy.com