2011-04-27 4 views
1

ID가 3과 4 인 카테고리를 내 breadcrumb 테마의 get_category_parents에서 제외시킬 방법을 찾고 있습니다. 이 코드입니다, 문제의 라인은 11 :카테고리를 get_category_parents (wordpress)에서 제외하십시오

내 머리 위로 떨어져, 그러나 나는 그것이 정확하다고 생각
function the_breadcrumb() { 
global $post; 
if (!is_home()) { 
    echo '<a href="'.get_option('home').'">'.home.'</a>'; 
    if (is_category()) { 
     echo "/"; 
     echo single_cat_title(); 
    } elseif(is_single() && !is_attachment()) { 
     $cat = get_the_category(); $cat = $cat[0]; 
     echo "/"; 
     echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); 
     echo "/"; 
     echo thman_get_limited_string($post->post_title,30); 
    }  
    elseif (is_search()) { 
     echo "/" . cerca; 
    }  
    elseif (is_page() && $post->post_parent) { 
     echo '/<a href="'.get_permalink($post->post_parent).'">'; 
     echo get_the_title($post->post_parent); 
     echo "</a>/"; 
     echo thman_get_limited_string($post->post_title,30);   
    } 
    elseif (is_page() OR is_attachment()) { 
     echo "/"; 
     echo thman_get_limited_string($post->post_title,30); 
    } 
    elseif (is_author()) { 
     echo wp_title('/Profilo'); 
     echo ""; 
    } 
    elseif (is_404()) { 
     echo "/"; 
     echo errore_404; 
    }  
    elseif (is_archive()) { 
     echo wp_title('/');  
    } 
} 
    } 

답변

2
$cat = get_the_category(); 
$cat = $cat[0]->term_id; 
// next will return an array of all category ancestors, with toplevel cat being [0] 
$ancestors = array_reverse(get_ancestors($cat, 'category')); 
if($ancestors) { 
    // set up output 
    $output = ''; 
    foreach($ancestors as $cat) { 
    // skips cats 3 and 4 
    if($cat == '3' || $cat == '4') continue; 
    $catlink = get_category_link($cat); 
    $catname = get_cat_name($cat); 
    $output .= '<a href="' . $catlink . '">' . $catname . '</a>' . "\n"; 
    } 
} 

echo $output; 

.

+0

+1 도움이 될 것입니다 희망 ... 우수 대답 셸리! 이것은 가장 확실하게 일을 마쳐야합니다! – tollmanz

+0

셸리 답변을 주셔서 감사합니다,하지만 난 PHP에서 전문가가 아니므로, 내 전체 코드는 아래의 것과 같아야합니까? – Fask

+0

오케이 - 용서해주세요 - 나는이 포럼에서 n00b에 속합니다. :) 아래 질문에 대해 "코멘트"링크를 찾을 수 없습니다! 하지만 네, 제가 준 코드는 "elseif (is_single() &&! is_attachment()) 섹션에있는 것들을 대체해야합니다 - 그리고 나는 그것이 당신이 가지고있는 것입니다. 다시 말하지만,이 코드는 머리 꼭대기에서 떨어져 있기 때문에 조금만 놀아야 할 수도 있습니다.하지만 올바른 코드라고 생각합니다. 희망은 도움이 :) – Shelly

0

답장을 보내 주셔서 감사합니다. 그러나 저는 PHP 전문가가 아니므로 전체 코드가 이렇게 보일 것입니다. 당신의 모든

function the_breadcrumb() { 
global $post; 
if (!is_home()) { 
    echo '<a href="'.get_option('home').'">'.home.'</a>'; 
    if (is_category()) { 
     echo "/"; 
     echo single_cat_title(); 
    } elseif(is_single() && !is_attachment()) { 
     $cat = get_the_category(); $cat = $cat[0]->term_id; 
    // next will return an array of all category ancestors, with toplevel cat being [0] 
    $ancestors = array_reverse(get_ancestors($cat, 'category'); 
    if($ancestors) { 
    // set up output 
    $output = ''; 
    foreach($ancestor as $cat) { 
    // skips cats 3 and 4 
    if($cat == '3' || $cat == '4') continue; 
    $catlink = get_category_link($cat); 
    $catname = get_cat_name($cat); 
    $output .= '<a href="' . $catlink . '">' . $catname . '</a>' . "\n"; 
    } 
    } 
    echo $output; 
     echo "/"; 
     echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); 
     echo "/"; 
     echo the_title_shorten(45,'...'); 
    }  
    elseif (is_search()) { 
     echo "/" . cerca; 
    }  
    elseif (is_page() && $post->post_parent) { 
     echo '/<a href="'.get_permalink($post->post_parent).'">'; 
     echo get_the_title($post->post_parent); 
     echo "</a>/"; 
     echo the_title_shorten(45,'...');  
    } 
    elseif (is_page() OR is_attachment()) { 
     echo "/"; 
     echo the_title_shorten(45,'...'); 
    } 
    elseif (is_author()) { 
     echo wp_title('/Profilo'); 
     echo ""; 
    } 
    elseif (is_404()) { 
     echo "/"; 
     echo errore_404; 
    }  
    elseif (is_archive()) { 
     echo wp_title('/');  
    } 
} 
    } 
0

감사합니다, 드디어 코드 작업을 진행 :

$ancestors = array_reverse(get_ancestors(get_cat_ID(single_cat_title("", false)), 'category')); 
$cat_parent_and_cat = ''; 
if($ancestors) { 
    foreach($ancestors as $cat) {    
     //if($cat == '3' || $cat == '4') continue; // skips cats 3 and 4 
     $catlink = get_category_link($cat); 
     $catname = get_cat_name($cat); 
     $cat_parent_and_cat .= '<a href="' . $catlink . '">' . $catname . '</a>' . ' &rsaquo; ' ; 
    } 
} 
echo $cat_parent_and_cat; 

이 누군가에게

관련 문제