I am using the Toolbox Theme from Digitech
I want to have breadcrumbs show up only on specific category posts. So if you go to a specific post under a certain category, I want the breadcrumb not to show.
I would like to not to show for just a few categories.
I know that it needs to be done in the single.php.
The breadcrumbs call is <?php if (function_exists('digi_breadcrumbs')) digi_breadcrumbs(); ?>
The breadcrumb.php is
<?php
function digi_breadcrumbs() {
$delimiter = '»';
$name = 'Home'; //text for the 'Home' link
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<p id="breadcrumbs">';
global $post;
$home = get_bloginfo('url');
echo 'You are here: <a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' ';
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
echo $currentBefore . 'Archive by category '';
single_cat_title();
echo ''' . $currentAfter;
} elseif ( is_day() ) {
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
echo $currentBefore . get_the_time('d') . $currentAfter;
} elseif ( is_month() ) {
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo $currentBefore . get_the_time('F') . $currentAfter;
} elseif ( is_year() ) {
echo $currentBefore . get_the_time('Y') . $currentAfter;
} elseif ( is_single() && !is_attachment() ) {
$cat = get_the_category(); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_attachment() ) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() && !$post->post_parent ) {
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_search() ) {
echo $currentBefore . 'Search results for '' . get_search_query() . ''' . $currentAfter;
} elseif ( is_tag() ) {
echo $currentBefore . 'Posts tagged '';
single_tag_title();
echo ''' . $currentAfter;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $currentBefore . 'Articles posted by ' . $userdata->display_name . $currentAfter;
} elseif ( is_404() ) {
echo $currentBefore . 'Error 404' . $currentAfter;
}
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
echo __('Page') . ' ' . get_query_var('paged');
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
}
echo '</p>';
}
}
?>
Navjot Singh answers:
Use in_category() conditional tag. Read about it on [[LINK href="http://codex.wordpress.org/Conditional_Tags#A_Category_Page"]]Codex[[/LINK]].
Julio Potier answers:
Hello
modify the script and do this if you want for example only breadcrumbs on cat ID 12:
if ( is_category(12) ) {
instead of
if ( is_category() ) {
This is line 17 of your script.
Codex link for the <em>is_category()</em> function : [[LINK href="http://codex.wordpress.org/Function_Reference/is_category"]]http://codex.wordpress.org/Function_Reference/is_category[[/LINK]]
see you
Francisco Javier Carazo Gil answers:
Hi Carlos,
You can pass the category or categories as parameter:
digi_breadcrumbs($categories)
And in this if you have to add this one:
if ( !is_home() && !is_front_page() || is_paged() && in_array(get_the_category() ,$categories) ) {
Sébastien | French WordpressDesigner answers:
you can use the solution of Julio but this solution is not complete.
It's ok for the template category.php but not for the template single.php
You could modify the script and do this if you want for example only breadcrumbs on cat ID 12:
if ( is_category(12) ) {
instead of
if ( is_category() ) {
elseif ( is_single() && in_category(12) && !is_attachment() ) {
instead of
elseif ( is_single() && !is_attachment() ) {
} elseif ( is_attachment() && in_category(12) ) {
instad of
} elseif ( is_attachment() ) {
the complete modified code will be :
<?php
function digi_breadcrumbs() {
$delimiter = '»';
$name = 'Home'; //text for the 'Home' link
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<p id="breadcrumbs">';
global $post;
$home = get_bloginfo('url');
echo 'You are here: <a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' ';
if ( is_category(12) ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
echo $currentBefore . 'Archive by category '';
single_cat_title();
echo ''' . $currentAfter;
} elseif ( is_day() ) {
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
echo $currentBefore . get_the_time('d') . $currentAfter;
} elseif ( is_month() ) {
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo $currentBefore . get_the_time('F') . $currentAfter;
} elseif ( is_year() ) {
echo $currentBefore . get_the_time('Y') . $currentAfter;
} elseif ( is_single() && in_category(12) && !is_attachment() ) {
$cat = get_the_category(); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_attachment() && in_category(12) ) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() && !$post->post_parent ) {
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_search() ) {
echo $currentBefore . 'Search results for '' . get_search_query() . ''' . $currentAfter;
} elseif ( is_tag() ) {
echo $currentBefore . 'Posts tagged '';
single_tag_title();
echo ''' . $currentAfter;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $currentBefore . 'Articles posted by ' . $userdata->display_name . $currentAfter;
} elseif ( is_404() ) {
echo $currentBefore . 'Error 404' . $currentAfter;
}
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
echo __('Page') . ' ' . get_query_var('paged');
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
}
echo '</p>';
}
}
?>
you can replace 12 by another ID, or by the name of your category : IE is_category('news')
if you want display the breadcrumb for the posts of the category 16 AND 17
you can use
is_category(16) && is_category(17)
same thing with in_category(16) && in_category(17)