2017-03-30 11 views
0

나는 woocmmerce에서 다음 및 이전 카테고리 링크와 이름을 얻는 데 문제가 있습니다. 실제로 나는 this하지만 발견 정상 워드 프레스 categorys 게시 단지에 대한 .. 나는 제품 카테고리에 대한 다음과 이전은 ... 어떤 help..i'll이다음 페이지로 이동하여 카테고리 카테고리 페이지에서 이전 링크를 찾으십시오.

내가 코드를 아래 tryd하지만, 전혀 논리적 먹으 렴을 appericated해야합니다. .. :

이것은 +1 카테고리 ID를 다시 실행합니다.하지만 예를 들어 카테고리 중 하나가 삭제되면 작동하지 않습니다.

답변

0

functions.php 에서 :

function woocommerce_next_prev_link() { 
if (is_product_category()){ 
    $taxonomy = 'product_cat'; 
    // Load all the terms for the product category 
    $terms = get_terms(array(
     'taxonomy' => $taxonomy, 
     'hide_empty' => FALSE, 
    )); 

    // Put all of the category id's into a simple array for searching 
    $ids = array(); 
    foreach($terms as $term) { 
     $ids[] = $term->term_id; 
    } 
    global $wp_query; 
    $cat_obj = $wp_query->get_queried_object(); 

    // Load the current term ID from the current query 
    $this_term = $cat_obj->term_id; 
    // Find the term in the list of ID's 

    $this_position = array_search($this_term, $ids); 
    // Identify the previous term 
    $prev_position = $this_position - 1; 
    // Identify the next term 
    $next_position = $this_position + 1; 

    // IF the previous term exists, and is not "off" the list (the currently displayed term is not the first term), then display the link 
    if($prev_position >=0) { 
     $prev_id = array_slice($ids, $prev_position, 1); 
     $prev_term = get_term($prev_id[0], $taxonomy); 
     if ($prev_term) { 
      echo '<a href="' . get_term_link($prev_term->term_id, $taxonomy) . '">&laquo; ' . $prev_term->name . '</a>'; 
     } 
    } 

    // IF the next term exists, and is not "off" the list (the currently displayed term is not the last term), then display the link 
    if($next_position > 0 && $next_position < count($ids)) { 
     $next_id = array_slice($ids, $next_position, 1); 
     $next_term = get_term ($next_id[0], $taxonomy); 
     if ($next_term) { 
      echo '<a href="' . get_term_link($next_term->term_id, $taxonomy) . '">' . $next_term->name . ' &raquo;</a>'; 
     } 
    } 
} 

}

전화 테마 파일이 fuction를 :

woocommerce_next_prev_link();