How to remove the "edit this entry"? - php

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>

Related

Removing Order date from WooCommerce emails

I'm trying to remove the order date from the woocommerce emails, but as I'm not that confident in PHP I'm finding myself a bit stuck.
Below is some code I've found to a similar question (instead removing the order number but leaving the date...I want to do the opposite.
<?php
// Targetting specific email notificatoins
$email_ids = array('new_order', 'customer_on_hold_order');
$date = sprintf( '<time datetime="%s">%s</time>', $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) );
// Displaying order number except for "New Order" and "Customer On Hold Order" notifications
if( ! in_array($email->id, $email_ids) ){
$order_number = sprintf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() );
$date = '('.$date.')';
} else {
$date = __('Order date:', 'woocommerce') . ' ' . $date;
$order_number = '';
}
if ( $sent_to_admin ) {
$before = '<a class="link" href="' . esc_url(
$order->get_edit_order_url() ) . '">';
$after = '</a> ';
} else {
$before = '';
$after = ' ';
}
?>
<h2><?php echo $before . $order_number . $after . $date; ?></h2>
Managed to figure this one out myself...(although not sure it's good practice...but it works!)
Simply added a class to the h2 tag within your-child-theme/woocommerce/emails/email-order-details.php, like below:
<h2 class="fbc-time">
<?php
if ( $sent_to_admin ) {
$before = '<a class="link" href="' . esc_url( $order->get_edit_order_url() ) . '">';
$after = '</a>';
} else {
$before = '';
$after = '';
}
/* translators: %s: Order ID. */
echo wp_kses_post( $before . sprintf( __( 'Order #%s', 'woocommerce' ) . $after . ' <time datetime="%s">%s</time>', $order->get_order_number(), $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ) );
?>
Then selected the class in email-styles.php and used display: none

full path in breadcrumbs wordpress

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();

How to substring element inside html

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','&laquo %title',FALSE,'',20); ?></li>
Hope it helps you.
Taken from https://wordpress.org/support/topic/using-substr-to-limit-characters-in-post-title

Woocommerce removing a category from product page

I've recently been working with Rohil_PHPBeginner who has been excellent and solved a big problem i had.
I need to now remove a particular category from the category list on the woo commerce product page.
Example: https://www.artgiftedbygod.co.uk/online-art-shop/jane-brighton/dawn-2/
You will see the Title, Artist name (which Rohil_PHPBeginner) solved, Price, Description, Availability, Buy Button, and then categories.
I would like to show all categories except the Artist name as this is now displayed under its own section.
This is the code that is found on the PHP page:
<?php
/**
* Single Product Meta
*
* #author WooThemes
* #package WooCommerce/Templates
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $post, $product;
$cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
$tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );
?>
<div class="product_meta">
<?php do_action( 'woocommerce_product_meta_start' ); ?>
<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
<span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span>. </span>
<?php endif; ?>
<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '.</span>' ); ?>
<?php echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' ); ?>
<?php do_action( 'woocommerce_product_meta_end' ); ?>
`
Try this :
<?php
/**
* Single Product Meta
*
* #author WooThemes
* #package WooCommerce/Templates
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $post, $product;
$cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
$tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );
?>
<div class="product_meta">
<?php do_action( 'woocommerce_product_meta_start' ); ?>
<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
<span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span>.</span>
<?php endif; ?>
<?php
$cat_array = array();
$term_list = wp_get_post_terms($post->ID, 'product_cat', array("fields" => "all")); //get array containing category details
foreach($term_list as $cat_list)
{
array_push($cat_array, $cat_list->term_id);
}
$cat_id = ($term_list[0]->parent); //get parent category ID from the above generated array
$termchildren = get_term_children( '90' , 'product_cat' ); //New Line in Updattion -1
$final_result = array_diff($cat_array,$termchildren);
$new_ary = array_values($final_result);
$final_result_size = sizeof($new_ary);
$i=0;$j=0;
for($i=0;$i<$final_result_size;$i++){
$new_cat_id = $new_ary[$i];
$cat_url = get_term_link ($new_cat_id, 'product_cat'); //get link of parent ID
$term = get_term( $new_cat_id, 'product_cat' ); //Get Name of the parent from the parent ID
$name = $term->name; //Store it into an varialbe
if($j == 0):
echo "Categories: ";
endif;
echo "<a href='".esc_url($cat_url)."'>".$name."</a>";
if($i == ($final_result_size-1)):
echo "";
else:
echo ", ";
endif;
$j++;
}
?>
<?php echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' ); ?>
<?php do_action( 'woocommerce_product_meta_end' ); ?>
</div>

I want to add "Category" to my WP breadcrumbs

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(); ?>

Categories