I want to take a full path in bread crumbs in the wordpress template
Now displays only the home page and category
I want the home - category - the title of the article with the link to this page, with a working schema markup
now the code looks like this
version Wordpress 4.8.1
function barcelona_breadcrumb() {
if ( barcelona_get_option( 'show_breadcrumb' ) != 'on' ) {
return;
}
$barcelona_post_type = is_single() ? get_post_type() : NULL;
$barcelona_sep_icon = '';
$barcelona_items = '';
if ( ( is_single() && $barcelona_post_type == 'post' && ! is_attachment() ) || is_category() ) {
$barcelona_categories = is_category() ? array() : get_the_category();
$barcelona_current_cat = $barcelona_last_cat = is_category() ? get_queried_object() : $barcelona_categories[0];
$barcelona_counter = 3;
while ( $barcelona_current_cat->category_parent != '0' ) {
$barcelona_current_cat = get_category( $barcelona_current_cat->category_parent );
$barcelona_items = $barcelona_sep_icon .'<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="'. esc_url( get_category_link( $barcelona_current_cat ) ) .'"><span itemprop="name">'. esc_html( $barcelona_current_cat->name ) .'</span></a><meta itemprop="position" content="%'. $barcelona_counter .'%" /></li>'. $barcelona_items;
$barcelona_counter++;
}
$barcelona_items .= $barcelona_sep_icon .'<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><'. ( is_category() ? 'span' : 'a href="'. esc_url( get_category_link( $barcelona_last_cat ) ) .'"' ) .' itemprop="item"><span itemprop="name">'. esc_html( $barcelona_last_cat->name ) .'</span></'. ( is_category() ? 'span' : 'a' ) .'><meta itemprop="position" content="%2%" /></li>';
if ( $barcelona_counter > 3 ) {
$barcelona_arr = array_reverse( range( 2, $barcelona_counter - 1 ) );
foreach( $barcelona_arr as $k => $v ) {
$barcelona_items = str_replace( 'itemprop="position" content="%'. intval( $k + 2 ) .'%"', 'itemprop="position" content="'. intval( $v ) .'"', $barcelona_items );
}
} else {
$barcelona_items = str_replace( 'content="%2%"', 'content="2"', $barcelona_items );
}
} else if ( is_archive() || is_search() ) {
$barcelona_title = is_search() ? esc_html__( 'Search Results', 'barcelona' ) : esc_html( get_the_archive_title() );
if ( is_author() ) {
$barcelona_title = esc_html__( 'Author Archive', 'barcelona' );
} else if ( is_year() ) {
$barcelona_title = esc_html__( 'Yearly Archive', 'barcelona' );
} else if ( is_month() ) {
$barcelona_title = esc_html__( 'Monthly Archive', 'barcelona' );
} else if ( is_day() ) {
$barcelona_title = esc_html__( 'Daily Archive', 'barcelona' );
} else if ( is_tag() ) {
$barcelona_title = esc_html__( 'Tag Archive', 'barcelona' );
}
$barcelona_items .= $barcelona_sep_icon .'<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="item"><span itemprop="name">'. $barcelona_title .'</span></span><meta itemprop="position" content="2" /></li>';
}
$barcelona_items = '<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="'. esc_url( home_url( '/' ) ) .'">'. esc_html__( 'Home', 'barcelona' ) .'</a><meta itemprop="position" content="1" /></li>'. $barcelona_items;
echo '<div class="breadcrumb-wrapper"><div class="container"><ol itemscope itemtype="http://schema.org/BreadcrumbList" class="breadcrumb">'. $barcelona_items .'</ol></div></div>';
}
Thanks!
Try with below code put below code in functions.php
function the_breadcrumbs() {
global $post;
if (!is_home()) {
echo "<a href='";
echo get_option('home');
echo "'>";
echo "Site's name here";
echo "</a>";
if (is_category() || is_single()) {
echo " > ";
$cats = get_the_category( $post->ID );
foreach ( $cats as $cat ){
echo $cat->cat_name;
echo " > ";
}
if (is_single()) {
the_title();
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
$anc_link = get_page_link( $post->post_parent );
foreach ( $anc as $ancestor ) {
$output = " > ".get_the_title($ancestor)." > ";
}
echo $output;
the_title();
} else {
echo ' > ';
echo the_title();
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"Archive: "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"Archive: "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"Archive: "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"Author's archive: "; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "Blogarchive: "; echo'';}
elseif (is_search()) {echo"Search results: "; }
}
Put below code in header.php
if(function_exists('the_breadcrumbs')) the_breadcrumbs();
Related
I am looking to take away some hyperlinks from the functions.php folder on my wordpress website.
I do not want any of the below to be clickable, only the text show. Is this possible to do?
} elseif ( is_tag() ) {
echo "<li typeof='v:Breadcrumb'>" . single_tag_title( '', false ) . '</li>';
} elseif ( is_day() ) {
echo __( "Archive", 'thrive' ) . ": ";
the_time( 'F jS, Y' );
echo '</li>';
} elseif ( is_month() ) {
echo __( "Archive", 'thrive' ) . ": ";
the_time( 'F, Y' );
echo '</li>';
} elseif ( is_year() ) {
echo __( "Archive", 'thrive' ) . ": ";
the_time( 'Y' );
echo '</li>';
} elseif ( is_author() ) {
echo __( "Author's archive", 'thrive' ) . ": ";
echo '</li>';
} elseif ( isset( $_GET['paged'] ) && ! empty( $_GET['paged'] ) ) {
echo __( "Archive", 'thrive' ) . ": ";
echo '';
} elseif ( is_search() ) {
echo __( "Search results", 'thrive' ) . ": ";
} elseif ( is_archive() ) {
echo __( "Archive", 'thrive' ) . ": ";
}
I appreciate any tips!
Many thanks!
I found this thread which describes exactly my problem but I tried the solution and it doesn't work.
Here is my front-page.php code:
<?php
get_header();
/* Wrapper start */
echo '<div class="main">';
$big_title = get_stylesheet_directory() . '/inc/shop_isle_big_title_section.php';
load_template( apply_filters( 'shop-isle-subheader', $big_title ) );
And here my shop_isle_big_title_section.php:
<?php
/**
* Big title section
*
* #package ShopIsle
* #since 1.0.0
*/
$shop_isle_homepage_slider_shortcode = get_theme_mod( 'shop_isle_homepage_slider_shortcode' );
$shop_isle_big_title_hide = get_theme_mod( 'shop_isle_big_title_hide' );
if ( isset( $shop_isle_big_title_hide ) && $shop_isle_big_title_hide != 1 ) {
echo '<section id="home" class="home-section home-parallax home-fade' . ( empty( $shop_isle_homepage_slider_shortcode ) ? ' home-full-height' : ' home-slider-plugin' ) . '">';
} elseif ( is_customize_preview() ) {
echo '<section id="home" class="home-section home-parallax home-fade shop_isle_hidden_if_not_customizer' . ( empty( $shop_isle_homepage_slider_shortcode ) ? ' home-full-height' : ' home-slider-plugin' ) . '">';
}
if ( ! empty( $shop_isle_homepage_slider_shortcode ) ) {
echo do_shortcode( $shop_isle_homepage_slider_shortcode );
} else {
$shop_isle_big_title_image = get_theme_mod( 'shop_isle_big_title_image', get_template_directory_uri() . '/assets/images/background-video.jpg' );
$shop_isle_big_title_title = get_theme_mod( 'shop_isle_big_title_title', 'Test' );
$shop_isle_big_title_subtitle = get_theme_mod( 'shop_isle_big_title_subtitle', __( 'WooCommerce Theme', 'shop-isle' ) );
if ( ! empty( $shop_isle_big_title_image ) ) {
echo '<div class="hero-slider">';
echo '<ul class="slides">';
//echo '<li class="bg-dark" style="background-image:url(' . esc_url( $shop_isle_big_title_image ) . ')">';
echo '<div class="home-slider-overlay"></div>';
echo '<div class="hs-caption">';
echo '<div class="caption-content">';
if ( ! empty( $shop_isle_big_title_title ) ) {
echo '<h1 class="hs-title-size-4 font-alt mb-30">Test Custom</h1>';
} elseif ( is_customize_preview() ) {
echo '<h1 class="hs-title-size-4 font-alt mb-30"></h1>';
}
if ( ! empty( $shop_isle_big_title_subtitle ) ) {
echo '<div class="hs-title-size-1 font-alt mb-40">Custom Sub</div>';
} elseif ( is_customize_preview() ) {
echo '<div class="hs-title-size-1 font-alt mb-40"></div>';
}
shop_isle_big_title_section_display_button();
echo '</div><!-- .caption-content -->';
echo '</div><!-- .hs-caption -->';
echo '</li><!-- .bg-dark -->';
echo '</ul><!-- .slides -->';
echo '</div><!-- .hero-slider -->';
}
}// End if().
echo '</section >';
As you can see the big title should normally display the text "Test Custom" and "Custom sub" and with no background, which it doesn't. I hope someone can see what I did wrong. What I want is that my changes are showed, which it does not in this case (yes my child theme is working correctly).
I am trying to remove the following lines
<p><?php edit_post_link(__('Edit this entry','express'),''); ?></p>
from the rest of the following code:
<section class="postmetadata clearfix">
<?php
if ( !is_page() && !is_attachment() ) {
$options = get_option( 'express_theme_options' );
$time = '<time datetime=' . get_the_time('Y-m-d') . '>' . get_the_time('j F Y') . '</time>';
$categories = get_the_category_list( __(', ', 'express') );
$tags = get_the_tag_list( __('and tagged ', 'express'),', ' );
$author_name = get_the_author_meta('display_name');
$author_ID = get_the_author_meta('ID');
$author_link = '' . $author_name . '';
$author = sprintf( __( 'by %s', 'express' ), $author_link );
if ( isset( $options['post-author'] ) && $options['post-author'] ) {
if ( is_singular() ) {
$postmeta = __('Posted in %1$s on %2$s %3$s %4$s', 'express');
} elseif ( 'chat' == get_post_format() ) {
$postmeta = __( 'Filed under %1$s %2$s %3$s', 'express' );
} elseif ( 'gallery' == get_post_format() || 'image' == get_post_format() ) {
$postmeta = __( 'Displayed in %1$s %2$s %3$s', 'express' );
} else {
$postmeta = __('Posted in %1$s %2$s %3$s', 'express');
}
} else {
if ( is_singular() ) {
$postmeta = __('Posted in %1$s on %2$s %3$s', 'express');
} elseif ( 'chat' == get_post_format() ) {
$postmeta = __( 'Filed under %1$s %2$s', 'express' );
} elseif ( 'gallery' == get_post_format() || 'image' == get_post_format() ) {
$postmeta = __( 'Displayed in %1$s %2$s', 'express' );
} else {
$postmeta = __('Posted in %1$s %2$s', 'express');
}
}
if ( is_singular() ) {
printf( $postmeta, $categories, $time, $tags, $author );
} else {
printf( $postmeta, $categories, $tags, $author );
}
?>
<br />
<?php
if ( comments_open() ) :
echo '<p>';
comments_popup_link(__('No Comments »','express'), __('One Comment »','express'), __('% Comments »','express'), __('Comments are closed.', 'express'));
echo '</p>';
endif;
?>
<?php } elseif ( is_attachment() ) {
$imagemeta = wp_get_attachment_metadata();
$time = '<time datetime=' . get_the_time('Y-m-d') . '>' . get_the_time('j F Y') . '</time>';
$image_url = wp_get_attachment_url();
$parent_title = get_the_title( $post->post_parent );
$parent_link = '' . esc_attr( $parent_title ) . '';
printf( __( 'Attached to %1$s which was posted on %2$s.' , 'express' ), $parent_link, $time );
echo '<br />';
echo '<a href="' . esc_url_raw( $image_url ) . '" title="' . __( 'Link to full-size image.', 'express' ) . '">';
_e( 'View full image.', 'express' );
echo '</a>';
}
if ( is_singular() || is_page() ) { ?>
<p><?php edit_post_link(__('Edit this entry','express'),''); ?></p>
<?php } ?>
</section>
I intend to use the "edit this entry" link at the bottom and the rest of the code right at the top of the page. But when I remove the
if ( is_singular() || is_page() ) { ?>
<p><?php edit_post_link(__('Edit this entry','express'),''); ?></p>
<?php } ?>
my Wordpress page breaks. It should be a syntax error, but I cannot find the right way to separate this part of the code from others.
Any ideas will be appreciated.
Thanks
You accidentally deleted some tags that have to stay.
if ( is_singular() || is_page() ) { ?> <- this one has to stay
Try this:
<section class="postmetadata clearfix">
<?php
if ( !is_page() && !is_attachment() ) {
$options = get_option( 'express_theme_options' );
$time = '<time datetime=' . get_the_time('Y-m-d') . '>' . get_the_time('j F Y') . '</time>';
$categories = get_the_category_list( __(', ', 'express') );
$tags = get_the_tag_list( __('and tagged ', 'express'),', ' );
$author_name = get_the_author_meta('display_name');
$author_ID = get_the_author_meta('ID');
$author_link = '' . $author_name . '';
$author = sprintf( __( 'by %s', 'express' ), $author_link );
if ( isset( $options['post-author'] ) && $options['post-author'] ) {
if ( is_singular() ) {
$postmeta = __('Posted in %1$s on %2$s %3$s %4$s', 'express');
} elseif ( 'chat' == get_post_format() ) {
$postmeta = __( 'Filed under %1$s %2$s %3$s', 'express' );
} elseif ( 'gallery' == get_post_format() || 'image' == get_post_format() ) {
$postmeta = __( 'Displayed in %1$s %2$s %3$s', 'express' );
} else {
$postmeta = __('Posted in %1$s %2$s %3$s', 'express');
}
} else {
if ( is_singular() ) {
$postmeta = __('Posted in %1$s on %2$s %3$s', 'express');
} elseif ( 'chat' == get_post_format() ) {
$postmeta = __( 'Filed under %1$s %2$s', 'express' );
} elseif ( 'gallery' == get_post_format() || 'image' == get_post_format() ) {
$postmeta = __( 'Displayed in %1$s %2$s', 'express' );
} else {
$postmeta = __('Posted in %1$s %2$s', 'express');
}
}
if ( is_singular() ) {
printf( $postmeta, $categories, $time, $tags, $author );
} else {
printf( $postmeta, $categories, $tags, $author );
}
?>
<br />
<?php
if ( comments_open() ) :
echo '<p>';
comments_popup_link(__('No Comments »','express'), __('One Comment »','express'), __('% Comments »','express'), __('Comments are closed.', 'express'));
echo '</p>';
endif;
?>
<?php } elseif ( is_attachment() ) {
$imagemeta = wp_get_attachment_metadata();
$time = '<time datetime=' . get_the_time('Y-m-d') . '>' . get_the_time('j F Y') . '</time>';
$image_url = wp_get_attachment_url();
$parent_title = get_the_title( $post->post_parent );
$parent_link = '' . esc_attr( $parent_title ) . '';
printf( __( 'Attached to %1$s which was posted on %2$s.' , 'express' ), $parent_link, $time );
echo '<br />';
echo '<a href="' . esc_url_raw( $image_url ) . '" title="' . __( 'Link to full-size image.', 'express' ) . '">';
_e( 'View full image.', 'express' );
echo '</a>';
}
?>
</section>
I'm using the Avada theme in wordpress. I'm trying to add some post custom fields into the scrollover (shown by mouse hover). I tried to edit the template file that controls the scrollover but without success. I got an error message invalid ">".
I tried to use this code to show the custom field:
<?php echo get_post_meta( $post_id,'the_price',); ?>
The Avada function template is as follows:
if ( ! function_exists( 'avada_render_rollover' ) ) {
function avada_render_rollover( $post_id, $post_permalink = '', $display_woo_price = false, $display_woo_buttons = false, $display_post_categories = 'default', $display_post_title = 'default', $gallery_id = '' ) {
// Retrieve the permalink if it is not set
if ( ! $post_permalink ) {
$post_permalink = get_permalink( $post_id );
}
// Check if theme options are used as base or if there is an override for post categories
if ( 'enable' == $display_post_categories ) {
$display_post_categories = true;
} elseif ( 'disable' == $display_post_categories ) {
$display_post_categories = false;
} else {
$display_post_categories = ! Avada()->settings->get( 'cats_image_rollover' );
}
// Check if theme options are used as base or if there is an override for post title
if ( 'enable' == $display_post_title ) {
$display_post_title = true;
} elseif ( 'disable' == $display_post_title ) {
$display_post_title = false;
} else {
$display_post_title = ! Avada()->settings->get( 'title_image_rollover' );
}
// Set the link on the link icon to a custom url if set in page options
$icon_permalink = ( fusion_get_page_option( 'link_icon_url', $post_id ) != null ) ? fusion_get_page_option( 'link_icon_url', $post_id ) : $post_permalink;
if ( '' == fusion_get_page_option( 'image_rollover_icons', $post_id ) || 'default' == fusion_get_page_option( 'image_rollover_icons', $post_id ) ) {
if( ! Avada()->settings->get( 'link_image_rollover' ) && ! Avada()->settings->get( 'zoom_image_rollover' ) ) { // link + zoom
$image_rollover_icons = 'linkzoom';
} elseif( ! Avada()->settings->get( 'link_image_rollover' ) && Avada()->settings->get( 'zoom_image_rollover' ) ) { // link
$image_rollover_icons = 'link';
} elseif( Avada()->settings->get( 'link_image_rollover' ) && ! Avada()->settings->get( 'zoom_image_rollover' ) ) { // zoom
$image_rollover_icons = 'zoom';
} elseif( Avada()->settings->get( 'link_image_rollover' ) && Avada()->settings->get( 'zoom_image_rollover' ) ) { // link
$image_rollover_icons = 'no';
} else {
$image_rollover_icons = 'linkzoom';
}
} else {
$image_rollover_icons = fusion_get_page_option( 'image_rollover_icons', $post_id );
}
// Set the link target to blank if the option is set
$link_target = ( 'yes' == fusion_get_page_option( 'link_icon_target', $post_id ) || 'yes' == fusion_get_page_option( 'post_links_target', $post_id ) ) ? ' target="_blank"' : '';
?>
<div class="fusion-rollover">
<div class="fusion-rollover-content">
<?php if ( 'no' != $image_rollover_icons && 'product' != get_post_type( $post_id ) ) : // Check if rollover icons should be displayed ?>
<?php if ( 'zoom' != $image_rollover_icons ) : // If set, render the rollover link icon ?>
<a class="fusion-rollover-link" href="<?php echo $icon_permalink; ?>"<?php echo $link_target; ?>>Permalink</a>
<?php endif; ?>
<?php if ( 'link' != $image_rollover_icons ) : // If set, render the rollover zoom icon ?>
<?php
// Get the image data
$full_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'full' );
if ( ! is_array( $full_image ) ) {
$full_image = array();
$full_image[0] = '';
}
// If a video url is set in the post options, use it inside the lightbox
if ( fusion_get_page_option( 'video_url', $post_id ) ) {
$full_image[0] = fusion_get_page_option( 'video_url', $post_id );
}
?>
<?php if ( 'linkzoom' == $image_rollover_icons || '' === $image_rollover_icons ) : // If both icons will be shown, add a separator ?>
<div class="fusion-rollover-sep"></div>
<?php endif; ?>
<?php if ( $full_image[0] ) : // Render the rollover zoom icon if we have an image ?>
<?php
// Only show images of the clicked post
if ( 'individual' == Avada()->settings->get( 'lightbox_behavior' ) ) {
$lightbox_content = avada_featured_images_lightbox( $post_id );
$data_rel = sprintf( 'iLightbox[gallery%s]', $post_id );
// Show the first image of every post on the archive page
} else {
$lightbox_content = '';
$data_rel = sprintf( 'iLightbox[gallery%s]', $gallery_id );
}
?>
<a class="fusion-rollover-gallery" href="<?php echo $full_image[0]; ?>" data-id="<?php echo $post_id; ?>" data-rel="<?php echo $data_rel; ?>" data-title="<?php echo get_post_field( 'post_title', get_post_thumbnail_id( $post_id ) ); ?>" data-caption="<?php echo get_post_field( 'post_excerpt', get_post_thumbnail_id( $post_id ) ); ?>">Gallery</a><?php echo $lightbox_content; ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php if ( $display_post_title ) : // Check if we should render the post title on the rollover ?>
<h4 class="fusion-rollover-title"><a href="<?php echo $icon_permalink; ?>"<?php echo $link_target; ?>><?php echo get_the_title( $post_id ); ?></a></h4>
<?php endif; ?>
<?php
// Check if we should render the post categories on the rollover
if ( $display_post_categories ) {
// Determine the correct taxonomy
if ( 'post' == get_post_type( $post_id ) ) {
$post_taxonomy = 'category';
} elseif ( 'avada_portfolio' == get_post_type( $post_id ) ) {
$post_taxonomy = 'portfolio_category';
} elseif ( 'product' == get_post_type( $post_id ) ) {
$post_taxonomy = 'product_cat';
}
echo get_the_term_list( $post_id, $post_taxonomy, '<div class="fusion-rollover-categories">', ', ', '</div>' );
}
?>
<?php if ( $display_woo_price ) : // Check if we should render the woo product price ?>
<?php woocommerce_get_template( 'loop/price.php' ); ?>
<?php endif; ?>
<?php if ( $display_woo_buttons ) : // Check if we should render the woo "add to cart" and "details" buttons ?>
<div class="fusion-product-buttons">
<?php woocommerce_get_template( 'loop/add-to-cart.php' ); ?>
<span class="fusion-rollover-linebreak"></span>
<a class="fusion-show-details-button" href="<?php echo post_permalink(); ?>"><?php _e( 'Details', 'Avada' ); ?></a>
</div>
<?php endif; ?>
</div>
</div>
<?php
}
}
Usually to use $post_id you need first to declare global $post
I have a premium WordPress theme which has breadcrumbs by default, but it does not show Category (and Sub-Category) item when on post page: Home > Category > Sub-Category > Post Title
Instead it just displays like this: Home > Post Title
This is the function which handles breadcrumbs:
(I marked the part of the code that I think is important with this sign, to save you time: ==========>>)
// BREADCRUMBS
if ( ! function_exists( 'ishyoboy_get_breadcrumbs' ) ) {
function ishyoboy_get_breadcrumbs() {
global $ish_options, $ish_woo_id;
$return = '';
$return .= '<div class="ish-pb-breadcrumbs"><div><div>' . "\n";
if ( ! is_front_page() ) {
if ( function_exists('is_woocommerce') ) {
if ( !is_woocommerce() && !is_woocommerce_page() ){
$return .= '<a class="ish-pb-breadcrumbs-home" href="';
$return .= home_url();
$return .= '">';
$return .= '<span>' . __( 'Home', 'ishyoboy' ) . '</span>';
$return .= "</a> > ";
}
}
else{
$return .= '<a class="ish-pb-breadcrumbs-home" href="';
$return .= home_url();
$return .= '">';
$return .= '<span>' . __( 'Home', 'ishyoboy' ) . '</span>';
$return .= "</a> > ";
}
}
else {
$return .= '<span class="ish-pb-breadcrumbs-home">';
$return .= '<span>' . __( 'Home', 'ishyoboy' ) . '</span>';
$return .= "</span>";
}
if ( !is_front_page() && is_home() ) {
global $page;
$return .= $page->post_title;
}
if ( is_archive() && 'post' == get_post_type() && ! is_category() && ( !function_exists('is_woocommerce') || !is_woocommerce() ) ) {
$hpage = get_page( get_option( 'page_for_posts' ) );
if ( 'page' == get_option('show_on_front') && isset($hpage) && '' != $hpage ){
$return .= get_page_parents($hpage->ID, TRUE, ' > ', FALSE );
}
if ( is_day() ) :
$return .= sprintf( __( 'Daily Archives: %s', 'ishyoboy' ), '<span>' . get_the_date() . '</span>' );
elseif ( is_month() ) :
$return .= sprintf( __( 'Monthly Archives: %s', 'ishyoboy' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'ishyoboy' ) ) . '</span>' );
elseif ( is_year() ) :
$return .= sprintf( __( 'Yearly Archives: %s', 'ishyoboy' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'ishyoboy' ) ) . '</span>' );
else :
$return .= __( 'Archives', 'ishyoboy' );
endif;
}
else if ( is_archive() && 'post' != get_post_type() && ( !function_exists('is_woocommerce') || !is_woocommerce() ) ) {
$type = get_post_type( get_the_ID() );
$obj = get_post_type_object( $type );
if ( is_object( $obj ) ){
$return .= $obj->labels->name;
}
}
if ( (is_category() || is_single()) && ( ( !function_exists('is_woocommerce_page') || !function_exists('is_woocommerce' ) ) || ( !is_woocommerce() && !is_woocommerce_page() ) ) ) {
$post_id = ish_get_the_ID();
$post_type = get_post_type();
switch ($post_type){
case 'portfolio-post' :
$terms = get_the_terms($post_id, 'portfolio-category' );
$term = ( ! empty( $terms ) ) ? array_pop($terms) : '';
if (isset($ish_options['page_for_custom_post_type_portfolio-post']) && '-1' != $ish_options['page_for_custom_post_type_portfolio-post']){
$portfolio_page = get_page($ish_options['page_for_custom_post_type_portfolio-post']);
$separator = " > ";
$return .= ''.$portfolio_page->post_title.'' . $separator;
}
if ( ! empty( $term ) ){
$return .= get_term_parents($term->term_id, 'portfolio-category', TRUE, ' > ', FALSE );
}
break;
// from here ==========>>
case 'post' :
if ( is_category() ){
global $cat;
$category = get_category($cat);
if ( $category->parent && ( $category->parent != $category->term_id ) ){
$return .= get_category_parents($category->parent, TRUE, ' > ', FALSE );
}
$return .= single_cat_title('', false);
}
else{
$category = get_the_category();
if ( is_object( $category ) ){
$ID = $category[0]->cat_ID;
$return .= get_category_parents($ID, TRUE, ' > ', FALSE );
}
}
break;
// to here ==========>>
default :
$type = get_post_type( get_the_ID() );
$obj = get_post_type_object( $type );
if ( is_object( $obj ) ){
$return .= '' . $obj->labels->name . ' > ';
}
}
}
else if ( ( function_exists('is_woocommerce_page') && function_exists('is_woocommerce') ) && (is_woocommerce() || is_woocommerce_page() )){
ob_start();
woocommerce_breadcrumb(array(
'delimiter' => ' > ',
'wrap_before' => '',
'wrap_after' => '',
'before' => '',
'after' => '',
'home' => '<span class="ish-pb-breadcrumbs-home"><span>' . _x( 'Home', 'breadcrumb', 'woocommerce' ) . '</span></span>',
));
$return .= ob_get_contents();
ob_end_clean();
ob_end_flush();
}
else if (is_tax()){
if (is_tax('portfolio-category')){
$current_term = get_queried_object();
if ( !empty($current_term) ){
//var_dump($current_term);
if (isset($ish_options['page_for_custom_post_type_portfolio-post']) && '-1' != $ish_options['page_for_custom_post_type_portfolio-post']){
$portfolio_page = get_page($ish_options['page_for_custom_post_type_portfolio-post']);
$separator = " > ";
$return .= ''.$portfolio_page->post_title.'' . $separator;
}
if ($current_term->parent != 0 ){
$return .= get_term_parents($current_term->parent, 'portfolio-category', TRUE, ' > ', FALSE );
}
$return .= $current_term->name;
}
}
}
else if (is_page()){
global $post;
if ($post->post_parent != 0 ){
$return .= get_page_parents($post->post_parent, TRUE, ' > ', FALSE );
}
}
if (!function_exists('is_woocommerce_page') || !is_woocommerce_page()){
if(is_single()) {$return .= get_the_title();}
if(is_page()) {
global $post;
$frontpage = get_option('page_on_front');
if ( $frontpage && $frontpage == $post->ID){
/*$return .= '<a class="home" href="';
$return .= home_url();
$return .= '">';
$return .= '<span>' . __( 'Home', 'ishyoboy' ) . '</span>';
$return .= "</a>";*/
} else {
$return .= get_the_title();
}
}
if(is_tag()){ $return .= __( 'Tag: ', 'ishyoboy' ) . single_tag_title('',FALSE); }
if(is_404()){ $return .= __( '404 - Page not Found', 'ishyoboy' ); }
if(is_search()){ $return .= __( 'Search', 'ishyoboy' ); }
if(is_year()){ $return .= get_the_time('Y'); };
}
$return .= '</div></div></div>';
return $return;
}
}
if ( !function_exists('the_post_thumbnail_caption') ) {
function the_post_thumbnail_caption(){
$thumb = get_post_thumbnail_id();
if ( ! empty( $thumb ) ){
$thumb_object = get_post( $thumb );
if ( ! empty( $thumb_object ) ) {
echo '<div class="wp-caption"><p class="wp-caption-text">' . $thumb_object->post_excerpt . '</p></div>';
}
}
}
}
if ( !function_exists('get_the_post_thumbnail_caption') ) {
function get_the_post_thumbnail_caption(){
$thumb = get_post_thumbnail_id();
if ( ! empty( $thumb ) )
return get_post( $thumb )->post_excerpt;
return null;
}
}
if ( ! function_exists( 'ishyoboy_activate_fancybox_on_blog_single' ) ) {
function ishyoboy_activate_fancybox_on_blog_single() {
if ( is_singular() && !is_singular( 'product' ) ){
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var thumbnails = jQuery("a:has(img)").not(".nolightbox").filter( function() { return /\.(jpe?g|png|gif|bmp)$/i.test(jQuery(this).attr('href')) });
if ( thumbnails.length > 0){
thumbnails.addClass( 'openfancybox-image' ).attr( 'rel', 'fancybox-post-image-<?php the_ID() ?>');
}
});
</script>
<?php
}
}
}
add_action( 'wp_head', 'ishyoboy_activate_fancybox_on_blog_single' );
if ( ! function_exists( 'ishyoboy_dummy_functions' ) ) {
function ishyoboy_dummy_functions() {
if ( false ) {
posts_nav_link();
wp_link_pages();
$args = '';
add_theme_support( 'custom-header', $args );
add_theme_support( 'custom-background', $args );
}
}
}
And then I've made a change in code which generated the desired change - Category appeared in breadcrumbs: Home > Category > Sub-Category > Post Title
But on the Category archive page breadcrumbs look like this: Home > Category > Category
Live example: http://pigtelligent.com/science/
The change I've made in above-mentioned code:
case 'post' :
$terms = get_the_terms($post_id, 'category' );
$term = ( ! empty( $terms ) ) ? array_pop($terms) : '';
if ( ! empty( $term ) ){
$return .= get_term_parents($term->term_id, 'category', TRUE, ' > ', FALSE );
}
I know that for someone smarter this should be easy, but I've spent whole day trying to figure this out, so can you please help me? :)
Categories can get tricky fast as posts can have multiple categories, and category landing pages can access a lot of meta which can get misleading. Make sure you've reviewed the Template Hierarchy page on the codex and you've got a firm understanding of how WP handles taxonomy.
Use What The File to find out what template you're actually on as you might not be on a category page, causing is_category() to return false. You could be on a single (as the if statement wrapping the logic you pointed out is checking is_category() || is_single()), or you might need to add a check for is_archive().
My best suggestion is to figure out if you're on a category page first, then stop all that extra logic and just spit out the category's name. Not too much help, I know, but hopefully that'll point you in the right direction
function the_breadcrumb() {
global $post;
echo '<ul id="breadcrumbs">';
if (!is_home()) {
echo '<li><a href="';
echo get_option('home');
echo '">';
echo 'Home';
echo '</a></li><li class="separator"> / </li>';
if (is_category() || is_single()) {
echo '<li>';
the_category(' </li><li class="separator"> / </li><li> ');
if (is_single()) {
echo '</li><li class="separator"> / </li><li>';
the_title();
echo '</li>';
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
$title = get_the_title();
foreach ( $anc as $ancestor ) {
$output = '<li>'.get_the_title($ancestor).'</li> <li class="separator">/</li>';
}
echo $output;
echo '<strong title="'.$title.'"> '.$title.'</strong>';
} else {
echo '<li><strong> '.get_the_title().'</strong></li>';
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
echo '</ul>';
}
?>
Get using: <?php the_breadcrumb(); ?>