我会非常感谢任何关于我面包屑的建议。两天的头痛,我就是搞不明白。
我有一个静态页面的博客条目,我想包括url在面包屑。
mysite.com >博客>帖子
现在我有“mysite.com > post”
最坏的情况是删除home url并更改blog url,所以这个面包屑至少会显示blog url。
博客>帖子
下面的代码很好用,但它不显示"blog url“,因为它只称为" home ",但是我想包含一个echo或其他东西来显示名为blog的静态页面(home - blog - post )。
是否可以包括一个链接到一个页面,例如回显'Blog< /a>‘?甚至在面包屑之前将主页和位置移除为< href=/>我的站点< /a> >>我的博客< /a> >>,然后剩下的面包屑( post /类别)。
我的目标..。mysite.com >博客>帖子
谢谢!
function my_breadcrumb() {
$sep = ' › ';
if (!is_front_page()) {
// Start the breadcrumb with a link to your homepage
echo '<div class="x"><nav class="x">';
echo '<a href="';
echo get_option('home');
echo '">';
bloginfo('name');
echo '</a>' . $sep;
// Check if the current page is a category, an archive or a single page. If so show the category or archive name.
if (is_category() || is_single() ){
the_category('title_li=');
} elseif (is_archive() || is_single()){
if ( is_day() ) {
printf( __( '%s', 'text_domain' ), get_the_date() );
} elseif ( is_month() ) {
printf( __( '%s', 'text_domain' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'text_domain' ) ) );
} elseif ( is_year() ) {
printf( __( '%s', 'text_domain' ), get_the_date( _x( 'Y', 'yearly archives date format', 'text_domain' ) ) );
} else {
_e( 'Blog Archives', 'text_domain' );
}
}
// If the current page is a single post, show its title with the separator
if (is_single()) {
echo $sep;
the_title();
}
// If the current page is a static page, show its title.
if (is_page()) {
echo the_title();
}
// if you have a static page assigned to be you posts list page. It will find the title of the static page and display it. i.e Home >> Blog
if (is_home()){
global $post;
$page_for_posts_id = get_option('page_for_posts');
if ( $page_for_posts_id ) {
$post = get_page($page_for_posts_id);
setup_postdata($post);
the_title();
rewind_posts();
}
}
echo '</nav></div>';
}}
//
发布于 2018-05-15 05:18:40
显示预期url的Breadcrumb,如: mysite.com > blog > post
function my_breadcrumb() {
$sep = ' > ';
if (!is_front_page()) {
// Start the breadcrumb with a link to your homepage
echo '<div class="breadcrumbs">';
echo '<a href="';
echo get_option('home');
echo '">';
bloginfo('name');
echo '</a>' . $sep;
// Check if the current page is a category, an archive or a single page. If so show the category or archive name.
if (is_category() || is_single() ){
echo '<a href="'.get_site_url().'/blog">Blog</a>';
} elseif (is_archive() || is_single()){
if ( is_day() ) {
printf( __( '%s', 'text_domain' ), get_the_date() );
} elseif ( is_month() ) {
printf( __( '%s', 'text_domain' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'text_domain' ) ) );
} elseif ( is_year() ) {
printf( __( '%s', 'text_domain' ), get_the_date( _x( 'Y', 'yearly archives date format', 'text_domain' ) ) );
} else {
_e( 'Blog Archives', 'text_domain' );
}
}
// If the current page is a single post, show its title with the separator
if (is_single()) {
echo $sep;
the_title();
}
// If the current page is a static page, show its title.
if (is_page()) {
echo the_title();
}
// if you have a static page assigned to be you posts list page. It will find the title of the static page and display it. i.e Home >> Blog
if (is_home()){
global $post;
$page_for_posts_id = get_option('page_for_posts');
if ( $page_for_posts_id ) {
$post = get_page($page_for_posts_id);
setup_postdata($post);
the_title();
rewind_posts();
}
}
echo '</div>';
}
}希望这对你有用。
https://stackoverflow.com/questions/50341648
复制相似问题