2010-04-23 5 views
0

누군가 wp_get_archives를 사용하여 INCLUDE ONLY 카테고리를 지정하는 방법을 알고 있습니까? 카테고리를 지정하고 싶지만 그 결과를 월별로 나열하고 싶습니다.wp_get_archives (cat = id) <- 아카이브의 특정 ID를 식별하는 방법은 무엇입니까?

kwebble의 플러그인을 사용해 보았습니다. 또한 WP 포럼에서 다음을 찾았지만 카테고리 만 제외하는 것으로 보입니다. 아마도 그것을 포함하도록 수정 될 수 있습니까? 그것이 주어 졌다고해도, 나는 그것을 어떻게 부르는지 모르겠다. ...

미리 감사드립니다! 그것은 $exclude-$include을 변경하고 "NOT"키워드를 생략 단지 문제

function customarchives_where($x) { 

    global $wpdb; 

    $include = '1'; // category id to include 

    return $x . " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ($include)"; 

: 특정 코드를 수정

add_filter('getarchives_where', 'customarchives_where'); 
add_filter('getarchives_join', 'customarchives_join'); 

function customarchives_join($x) { 

    global $wpdb; 

    return $x . " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; 

} 

function customarchives_where($x) { 

    global $wpdb; 

    $exclude = '1'; // category id to exclude 

    return $x . " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id NOT IN ($exclude)"; 

답변

0

는 마지막 함수의 쿼리에서 전부 ... 다소 간단하다 리턴 쿼리. 하지만 그 카테고리를으로 모두 반환하는 대신 해당 카테고리 만을 반환합니다.

+0

functions.php에 넣을 수있는 것입니까? 이것을 위젯 안에 넣을 방법이 있습니까? – Matrym

+0

이 코드를 functions.php에 넣을 수는 있지만 사용자 정의 위젯을 빌드하는 데는 이보다 훨씬 많은 작업이 필요합니다. – EAMann

관련 문제