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).
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 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();
I'm stuck trying to get my site together in time for our launch.
We've got a wordpress plugin that displays a product based on selected inputs. Each variation has an image which is layered over top of each other and in pNG to create a final picture. It all works well on the product page http://tattersfield.co/online-tailor-store/double-breasted/luciano-79000-1-jacket/ but now I need the image to display in our Composite Product area http://tattersfield.co/online-tailor-store/three-piece-single-breasted-suit/test-3-piece-suit .
This is the code I need to update to display the plugin generated image instead of the product thumbnail.
<?php
/**
* Composited Product Image
* #version 3.0.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) )
exit;
if ( has_post_thumbnail( $product_id ) ) {
?><div class="composited_product_images"><?php
$image_title = esc_attr( get_the_title( get_post_thumbnail_id( $product_id ) ) );
$image_link = wp_get_attachment_url( get_post_thumbnail_id( $product_id ) );
$image = get_the_post_thumbnail( $product_id, apply_filters( 'woocommerce_composited_product_thumbnail_size', 'shop_catalog' ), array(
'title' => $image_title
) );
echo apply_filters( 'woocommerce_composited_product_image_html', sprintf( '%s', $image_link, $image_title, $image ), $product_id );
?></div><?php
}
And this is a snippet of the code from the plugin that displays the image. What do I need to do to get these 2 pieces to work together to display the image I'm after?
Frontend Single Product Page
============================= */
public function display_product_image() {
global $post, $jckpc_options;
$setImages = get_post_meta( $post->ID, $this->slug.'_images', true );
$defaults = get_post_meta( $post->ID, $this->slug.'_defaults', true );
$querySelectors = $_GET;
if(!empty($querySelectors)) {
$sanitisedQuerySelectors = array();
foreach($querySelectors as $attSlug => $attVal) {
$sanitisedQuerySelectors[$this->sanitise_str($attSlug)] = $this->sanitise_str($attVal);
}
$querySelectors = $sanitisedQuerySelectors;
}
$images = array();
if( $setImages['background'] && $setImages['background'] != '' ) {
$imgSrc = wp_get_attachment_image_src($setImages['background'], apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ));
$images[] = '<img id="'.$this->slug.'_image_background" src="'.$imgSrc[0].'">';
}
$setImages = array_reverse($setImages);
$img_i = 1; foreach($setImages as $attSlug => $attVals) {
$default = ( isset($defaults[$attSlug]) && isset($setImages[$attSlug][$defaults[$attSlug]]) ) ? $setImages[$attSlug][$defaults[$attSlug]] : false;
$default = ( isset($querySelectors[$attSlug]) && isset($setImages[$attSlug][$querySelectors[$attSlug]]) ) ? $setImages[$attSlug][$querySelectors[$attSlug]] : $default;
$images[$img_i] = '<div id="'.$this->slug.'_image_'.$attSlug.'">';
if($default) {
$imgSrc = wp_get_attachment_image_src($default, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ));
$images[$img_i] .= '<img src="'.$imgSrc[0].'">';
}
$images[$img_i] .= '</div>';
$img_i++;
}
// output images
echo '<style>';
echo '#jckpc_images {';
// width
echo "width: {$jckpc_options['image_container_width']['width']};";
// align
if($jckpc_options['image_container_align'] == "centre") {
echo "margin-left: auto; margin-right: auto;";
$jckpc_options['image_container_align'] = "none";
}
echo "float: {$jckpc_options['image_container_align']};";
// spacing
echo "margin-top: {$jckpc_options['image_container_margin']['margin-top']};";
echo "margin-right: {$jckpc_options['image_container_margin']['margin-right']};";
echo "margin-bottom: {$jckpc_options['image_container_margin']['margin-bottom']};";
echo "margin-left: {$jckpc_options['image_container_margin']['margin-left']};";
// padding
echo "padding-top: {$jckpc_options['image_container_padding']['padding-top']};";
echo "padding-right: {$jckpc_options['image_container_padding']['padding-right']};";
echo "padding-bottom: {$jckpc_options['image_container_padding']['padding-bottom']};";
echo "padding-left: {$jckpc_options['image_container_padding']['padding-left']};";
// background
echo "background: {$jckpc_options['image_container_background']};";
echo '}';
$horThumbSpacing = $jckpc_options['thumb_spacing']/2;
$verThumbSpacing = $jckpc_options['thumb_spacing'];
echo "#jckpc_thumbnails {";
echo "margin: {$verThumbSpacing}px -{$horThumbSpacing}px -{$verThumbSpacing}px;";
echo "}";
echo '#jckpc_thumbnails a {';
echo "float: left;";
echo "display: inline;";
$thumbWidth = 100/(int)$jckpc_options['thumb_cols_rows'];
echo "width: {$thumbWidth}%;";
// spacing
echo "padding: 0 {$horThumbSpacing}px {$verThumbSpacing}px;";
echo '}';
echo "#jckpc_image_wrap #jckpc_loading {";
// background
echo "background: {$jckpc_options['loading_overlay_colour']};";
echo "}";
echo "#jckpc_image_wrap #jckpc_loading i {";
$loadingIconMTop = 20/2;
echo "font-size: 20px;";
echo "line-height: 20px;";
echo "margin-top: -{$loadingIconMTop}px;";
echo "color: {$jckpc_options['loading_icon_colour']};";
echo "}";
// breakpoint
if($jckpc_options['enable_breakpoint']) {
echo "#media (max-width: {$jckpc_options['breakpoint']['width']}) {";
echo '#jckpc_images {';
// width
echo "width: {$jckpc_options['image_container_width_breakpoint']['width']};";
// align
if($jckpc_options['image_container_align_breakpoint'] == "centre") {
echo "margin-left: auto; margin-right: auto;";
$jckpc_options['image_container_align_breakpoint'] = "none";
}
echo "float: {$jckpc_options['image_container_align_breakpoint']};";
// spacing
echo "margin-top: {$jckpc_options['image_container_margin_breakpoint']['margin-top']};";
echo "margin-right: {$jckpc_options['image_container_margin_breakpoint']['margin-right']};";
echo "margin-bottom: {$jckpc_options['image_container_margin_breakpoint']['margin-bottom']};";
echo "margin-left: {$jckpc_options['image_container_margin_breakpoint']['margin-left']};";
echo "}";
echo "}";
}
echo '</style>';
echo '<div id="'.$this->slug.'_images">';
echo '<div id="'.$this->slug.'_image_wrap" data-loading="0">';
foreach($images as $image) {
echo $image;
}
echo '<div id="'.$this->slug.'_loading"><i class="jckpc-icn-'.$jckpc_options['loading_icon'].' animate-spin"></i></div>';
echo '</div>';
if($jckpc_options['show_thumbs']) $this->get_thumbnails();
echo '</div>';
}
public function get_thumbnails() {
global $post, $product, $woocommerce;
$attachment_ids = $product->get_gallery_attachment_ids();
if ( $attachment_ids ) {
echo '<div id="'.$this->slug.'_thumbnails">';
$loop = 0;
$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 3 );
foreach ( $attachment_ids as $attachment_id ) {
$classes = array( 'zoom' );
if ( $loop == 0 || $loop % $columns == 0 )
$classes[] = 'first';
if ( ( $loop + 1 ) % $columns == 0 )
$classes[] = 'last';
$image_link = wp_get_attachment_url( $attachment_id );
if ( ! $image_link )
continue;
$image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ) );
$image_class = esc_attr( implode( ' ', $classes ) );
$image_title = esc_attr( get_the_title( $attachment_id ) );
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '%s', $image_link, $image_class, $image_title, $image ), $attachment_id, $post->ID, $image_class );
$loop++;
}
echo '</div>';
}
}
public function get_image_data($pid, $atts) {
$imgData = array(
'prodid' => $pid
);
if(!empty($atts)){
foreach($atts as $attSlug => $attVal) {
if(substr($attSlug, 0, 10) != "attribute_") $attSlug = 'attribute_'.$attSlug;
$imgData[$attSlug] = sanitize_title_with_dashes($attVal);
}
}
I need to shorten the title in the previous and next buttons in a WP theme.
Here's the code:
<?php
/* ----------------------------------------------------------------------------------
Display navigation to next/previous pages when applicable.
---------------------------------------------------------------------------------- */
if ( ! function_exists( 'thinkup_input_nav' ) ) :
function thinkup_input_nav( $nav_id ) {
global $wp_query, $post;
// Don't print empty markup on single pages if there's nowhere to navigate.
if ( is_single() ) {
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous )
return;
}
// Don't print empty markup in archives if there's only one page.
if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
return;
?>
<nav role="navigation" id="<?php echo $nav_id; ?>">
<?php if ( is_single() ) : ?>
<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-icon"><i class="icon-angle-left icon-large"></i></span><span class="meta-nav">%title</span>' ); ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '<span class="meta-nav">%title</span><span class="meta-icon"><i class="icon-angle-right icon-large"></i></span>' ); ?>
<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous"><?php next_posts_link( __( 'Older posts', 'lan-thinkupthemes') ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts', 'lan-thinkupthemes') ); ?></div>
<?php endif; ?>
<?php endif; ?>
</nav><!-- #<?php echo $nav_id; ?> -->
<?php
}
endif;
/* ----------------------------------------------------------------------------------
Display navigation to next/previous image when applicable.
---------------------------------------------------------------------------------- */
if ( ! function_exists( 'thinkup_input_imagesnav' ) ) :
function thinkup_input_imagesnav() {
global $wp_query, $post;
?>
<nav role="navigation" id="nav-below">
<div class="nav-previous"><?php previous_image_link( 'false', '<div class="nav-previous"><span class="meta-icon"><i class="icon-angle-left icon-large"></i></span><span class="meta-nav">' . __( 'Previous', 'lan-thinkupthemes') . ' </span></div>' ); ?></div>
<div class="nav-next"><?php next_image_link( 'false', '<span class="meta-nav">' . __( 'Next', 'lan-thinkupthemes') . '</span><span class="meta-icon"><i class="icon-angle-right icon-large"></i></span>' ); ?></div>
</nav><!-- #image-navigation -->
<?php
}
endif;
/* Display comments at bottom of post, page and project pages. */
function thinkup_input_allowcomments() {
if ( comments_open() || '0' != get_comments_number() )
comments_template( '/comments.php', true );
}
/* ----------------------------------------------------------------------------------
Returns true if a blog has more than 1 category.
---------------------------------------------------------------------------------- */
function thinkup_input_categorizedblog() {
if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
// Create an array of all the categories that are attached to posts
$all_the_cool_cats = get_categories( array(
'hide_empty' => 1,
) );
// Count the number of categories that are attached to the posts
$all_the_cool_cats = count( $all_the_cool_cats );
set_transient( 'all_the_cool_cats', $all_the_cool_cats );
}
if ( '1' != $all_the_cool_cats ) {
return true;
} else {
return false;
}
}
/* Flush out the transients used in thinkup_input_categorizedblog. */
function thinkup_input_transient_flusher() {
delete_transient( 'all_the_cool_cats' );
}
add_action( 'edit_category', 'thinkup_input_transient_flusher' );
add_action( 'save_post', 'thinkup_input_transient_flusher' );
What I tried was to add substring to this line:
<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-icon"><i class="icon-angle-left icon-large"></i></span><span class="meta-nav">%title</span>' ); ?>
to:
<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-icon"><i class="icon-angle-left icon-large"></i></span><span class="meta-nav"><?php echo substr(%title,0,10)?></span>' ); ?>
but upon reloading the page it displayed an empty text instead.
What am I doing wrong?
You can override the previous_post_link() function in your functions.php file of your theme as like this :
function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '',$limit = -1) {
if ( is_attachment() )
$post = & get_post($GLOBALS['post']->post_parent);
else
$post = get_previous_post($in_same_cat, $excluded_categories);
if ( !$post )
return;
$title = apply_filters('the_title', $post->post_title, $post);
if ($limit>-1) {$title = substr($title,0,$limit).'…';}
$string = '<a href="'.get_permalink($post->ID).'">';
$link = str_replace('%title', $title, $link);
$link = $pre . $string . $link . '</a>';
$format = str_replace('%link', $link, $format);
echo $format;
And then you can call the function with the additional argument to define your desired trim length:
<li><?php previous_post_link('%link','« %title',FALSE,'',20); ?></li>
Hope it helps you.
Taken from https://wordpress.org/support/topic/using-substr-to-limit-characters-in-post-title
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(); ?>