logo

$5
exclude category frome breadcrumb function

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 = '<li class="crumb2">';
$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, '!@#$%^&*()');
//echo $var;
//var_dump($var);
$va = explode('!@#$%^&*()', $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('<a ', "<a style=\"margin-left: -10px; z-index: $z_i; padding-left: 35px; \" ", $v);
else $f_s_p .= str_replace('<a ', "<a style=\"margin-left: -10px; z-index: $z_i; padding-left: 16px; \" ", $v);
++$fg;
}
/*echo '<a href="">';
single_cat_title();
echo '</a>';*/
$f_s_p .= '</li>';

return $f_s_p;
}

function the_breadcrumb() {
$i = 0;
echo '<li class="crumb1">';
echo '<a href="';
echo get_option('home');
echo '">';
bloginfo('name');
echo "</a>";
echo '</li>';
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 = '<li class="crumb2">';
$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 .= '<a href="' . get_category_link($cat->term_id) . '">';
else $f_s_p .= '<a href="' . get_category_link($cat->term_id) . '" class="bclesspadding">';
$f_s_p .= $cat->cat_name;
$f_s_p .= '</a>';
}
else{
if($key == 0) $f_s_p .= '<a href="' . get_category_link($cat->term_id) . '" class="noarrow">';
else $f_s_p .= '<a href="' . get_category_link($cat->term_id) . '" class="noarrow bclesspadding">';
$f_s_p .= $cat->cat_name;
$f_s_p .= '</a>';
}
}
$f_s_p .= '</li>';

echo $f_s_p;
}
define('F_S_P', $f_s_p);

endif;
/*echo '<li class="crumb2">';
the_category(' ', 'single');
echo '</li>';*/

/*echo '<li class="crumb3">';
echo '<a href="">';
the_title();
echo '</a>';
echo '</li>';*/
}
} elseif (is_page()) {
echo '<li class="crumb2">';
echo '<a href="">';
echo the_title();
echo '</a>';
echo '</li>';
}
}
}


I tried replacing get_the_category with this function:

foreach((get_the_category()) as $cat) { if (!($cat->cat_ID==618)) echo '<a href="' . get_bloginfo('url') . '/category/' . $cat->category_nicename . '/">'. ' - ' . $cat->cat_name . '</a>';}


but it doesn't work in the foreach() condition

paul de wouters | 06/05/10 at 12:52pm | Edit


(2) Possible Answers Submitted...

  • avatar
    Last edited:
    06/05/10
    1:30pm
    Oleg Butuzov says:

    foreach (get_the_category() as $cat){
    if (!($cat->cat_ID==618)) {
    echo '<a href="' . get_bloginfo('url') . '/category/' . $cat->category_nicename . '/">'. ' - ' . $cat->cat_name . '</a>';
    }
    }

    • 06/05/10 1:59pm

      paul de wouters says:

      the problem is replacing get_the_category here:


      foreach((get_the_category()) as $key => $cat) {//var_dump($cat);


      I think that's what I need to do, not sure though

  • avatar
    Last edited:
    06/07/10
    11:32am
    B L says:

    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 = '<li class="crumb2">';

    $var = get_category_parents($ca, TRUE, '!@#$%^&*()');
    $va = explode('!@#$%^&*()', $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('<a ', "<a style=\"margin-left: -10px; z-index: $z_i; padding-left: 35px; \" ", $v);
    else $f_s_p .= str_replace('<a ', "<a style=\"margin-left: -10px; z-index: $z_i; padding-left: 16px; \" ", $v);
    ++$fg;
    }
    $f_s_p .= '</li>';
    }
    return $f_s_p;

    }

This question has expired.





Current status of this question: Completed