I need to exclude a category from the_breadcrumb() function, the get_category function doesn't allow to exclude categories through arguments.
function breadcrumb_cat_path(){
$f_s_p = ' ';
$ca = get_query_var('cat');
if(!$ca){
foreach((get_the_category()) as $key => $cat) {
$ca = $cat->term_id;
}
}
//var_dump($ca);
$var = get_category_parents($ca, TRUE, '[email protected]#$%^&*()');
//echo $var;
//var_dump($var);
$va = explode('[email protected]#$%^&*()', $var);
array_pop($va);
//var_dump($va);
$z_i = 3 + count($va);
$fg = 0;
foreach($va as $k => $v){
--$z_i;
if($fg == 0) $f_s_p .= str_replace('';
single_cat_title();
echo '';*/
$f_s_p .= '';
return $f_s_p;
}
function the_breadcrumb() {
$i = 0;
echo '';
echo '';
bloginfo('name');
echo "";
echo '';
if (!is_home()) {
if (is_category() || is_single()) {
if(is_category()){
$f_s_p = breadcrumb_cat_path();
echo $f_s_p;
}
if (is_single()) {
//f_s_p stands for the footer_single_problem which occurs on single post pages
//var_dump($f_s_p);
if(defined('F_S_P')):
echo F_S_P;
else:
static $f_s_p = '';
$count = count(get_the_category());
if($count == 1){
$f_s_p = breadcrumb_cat_path();
echo $f_s_p;
}
else{
foreach((get_the_category()) as $key => $cat) {//var_dump($cat);
if($key == $count - 1){
if($key == 0) $f_s_p .= '';
else $f_s_p .= '';
$f_s_p .= $cat->cat_name;
$f_s_p .= '';
}
else{
if($key == 0) $f_s_p .= '';
else $f_s_p .= '';
$f_s_p .= $cat->cat_name;
$f_s_p .= '';
}
}
$f_s_p .= '';
echo $f_s_p;
}
define('F_S_P', $f_s_p);
endif;
/*echo '';
the_category(' ', 'single');
echo '';*/
/*echo '';
echo '';
the_title();
echo '';
echo '';*/
}
} elseif (is_page()) {
echo '';
echo '';
echo the_title();
echo '';
echo '';
}
}
}
I tried replacing get_the_category with this function:
foreach((get_the_category()) as $cat) { if (!($cat->cat_ID==618)) echo ''. ' - ' . $cat->cat_name . '';}
but it doesn't work in the foreach() condition
Solution - 1
You could try this (i've not tested it though):
function breadcrumb_cat_path(){
$f_s_p='';
$ca = get_query_var('cat');
if(!$ca){
foreach((get_the_category()) as $key => $cat) {
$ca = $cat->term_id;
}
}
if ($ca!=618) {
$f_s_p = ' ';
$var = get_category_parents($ca, TRUE, '[email protected]#$%^&*()');
$va = explode('[email protected]#$%^&*()', $var);
array_pop($va);
$z_i = 3 + count($va);
$fg = 0;
foreach($va as $k => $v){
--$z_i;
if($fg == 0) $f_s_p .= str_replace('
Solution - 2
foreach (get_the_category() as $cat){
if (!($cat->cat_ID==618)) {
echo ''. ' - ' . $cat->cat_name . '';
}
}
|