I would be very thankful for any suggestions about my breadcrumb. 2 days of headaches and I just can't figure it out.
I have a static page for blog entries and I would like to include the url in the breadcrumb.
mysite.com > blog > post
Right now I have " mysite.com > post"
Worst case scenario remove home url and to change for blog url, so this breadcrumb displays at least the blog url.
Blog > post
Following code works great but it doesn't display "blog url" as it only calls "home", but I would like to include an echo or something to display the static page called blog after home (home - blog - post ).
Would it be possible to include a link to a page for instance like echo 'Blog< /a>' ? Or even remove home and place before breadcrumb as < a href=/> My Site < /a> >> < a href =/blog> My Blog < /a> >> then rest of breadcrumb ( post / category ).
My goal... mysite.com > blog > post
Thanks !
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>';
}
}
//
- note. I am curious as why the posts page isn't showing as code says it should as Home >> Blog. ( I created a page called blog, and then settings - reading - posts page and using home.php as template ). (Front page is using a page called welcome, then settings - reading- front page, template is front-page.php ). ** I am making my own theme and I wouldn't like to add more plugins.