2013-08-28 2 views
1

WordPress core 파일을 수정하지 않고도 wordpress 카테고리/아카이브 widget html 출력을 수정할 수 있습니까?PHP/Wordpress : 카테고리 위젯 출력

<aside><h4>Title</h4><ul><li class="cat-item cat-item-11"><a href="#">123</a> (1)</li></ul></aside> 

그리고 내가 무엇을 달성하기 위해 노력하고있어 :

<aside><h4>Title</h4><ul><li class="cat-item cat-item-11"><a href="#">123</a> <span class="number">[1]<span></li></ul></aside> 

답변

0

을 당신은 위젯 카테고리의 출력을 변경하려면 필터 widget_categories_dropdown_argswidget_categories_args이 예를 들어 나는이 출력 코드가 있습니다.
예 :

그리고 아카이브 위젯 https://wordpress.stackexchange.com/a/25002/12615, widget_archives_dropdown_argswidget_archives_args.
예 : https://wordpress.stackexchange.com/q/19945/12615

+0

당신이 순서대로 나는 효과를 설명한 달성하기 위해 그것을 사용하는 방법의 예를 제공하시기 바랍니다 수 있습니까? widget_categories_args에 대해 읽었지만 수정할 매개 변수를 아직 모릅니다. – vlad

0
/* 
* Add spans around category counters 
*/ 
function _thz_filter_wp_list_categories($output, $args) { 

    if($args['show_count']){ 
     $re = '/<\/a>(.*?)<\/li>/s'; 
     preg_match_all($re, $output, $matches); 

     if(!empty($matches) && isset($matches[1])){ 
      foreach($matches[1] as $between){ 
       $between = strip_tags($between); 
       $output  = str_replace($between,'<span class="count">'.$between.'</span>',$output); 
      } 
     } 
    } 

    return $output; 
} 

add_filter('wp_list_categories', '_thz_filter_wp_list_categories',10,2); 

/* 
* Add spans around archive counters 
*/ 
function _thz_filter_get_archives_link($output) { 

    $re = '/<\/a>(.*?)<\/li>/s'; 
    preg_match_all($re, $output, $matches); 

    if(!empty($matches) && isset($matches[1])){ 
     foreach($matches[1] as $between){ 
      $between = strip_tags($between); 
      $output = str_replace($between,'<span class="count">'.$between.'</span>',$output); 
     } 
    } 

    return $output; 
}; 

add_filter('get_archives_link', '_thz_filter_get_archives_link', 10, 6); 
관련 문제