2012-12-15 2 views
3

내 사이트에 태그를 표시 할 수 있도록 "가장 인기있는 태그"라는 플러그인이 있지만 일반 태그가 많이 표시됩니다. 내가 추가 할 수있는 코드가있어서 원하지 않는 태그를 제외시키는 옵션으로 내 사이트에서 가장 인기있는 태그를 표시 할 수 있습니까? 또는 이것을 허용하는 플러그인?가장 인기있는 태그를 표시 하시겠습니까?

+0

WP의 위젯 메뉴를 통해 구성 할 수 없습니까? – BenM

+0

@BenM 플러그인 또는 플러그인이 필요하지 않습니까? –

답변

1

이 코드는 지난 30 일 동안 가장 많이 사용 된 태그를 반환합니다. 약간의 jQuery와 CSS를 사용하여 예를 들어 처음 글꼴에 큰 글꼴 크기를 넣고 마지막 글꼴 크기에 작은 글꼴 크기를 넣을 수 있습니다.

<ul id="footer-tags"> 
    <?php $wpdb->show_errors(); ?> 
    <?php 
     global $wpdb; 
     $term_ids = $wpdb->get_col(" 
      SELECT term_id FROM $wpdb->term_taxonomy 
      INNER JOIN $wpdb->term_relationships ON $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id 
      INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id 
      WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= $wpdb->posts.post_date"); 

if(count($term_ids) > 0){ 

    $tags = get_tags(array(
    'orderby' => 'count', 
    'order' => 'DESC', 
    'number' => 28, 
    'include' => $term_ids, 
)); 

foreach ((array) $tags as $tag) { 
    echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a></li>'; 
} 
} 
?> 
</ul> 
2

get_tags-> count는 실제로 범위의 태그를 계산하지 않는다고 생각합니다. 나는이 솔루션을 구현 한이 당신을 위해 작동하는지 알려 주시기 바랍니다 :

<?php 
global $wpdb; 
$term_ids = $wpdb->get_col(" 
SELECT term_id , count(*) cont FROM $wpdb->term_taxonomy 
INNER JOIN $wpdb->term_relationships ON $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id 
INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id 
WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= $wpdb->posts.post_date AND $wpdb->term_taxonomy.taxonomy='post_tag' 
GROUP BY term_id 
ORDER BY cont DESC 
LIMIT 5"); 

if(count($term_ids) > 0){ 
    $tags = get_tags(array(
    'orderby' => 'count', 
    'order' => 'DESC', 
    'number' => 5, 
    'include' => $term_ids, 
)); 
foreach ((array) $tags as $tag) { 
    echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a></li>'; 
} 
} 
?> 
1

나는 사용자 정의 쿼리 나 플러그인을 작성 포함 볼 수있는 솔루션을. 특정 플러그인에 대해 묻는 동안 순수 WP를 통해이 작업을 수행 할 수 있습니다.

첫째, 같은 wp_tag_cloud를 사용하여 태그 클라우드를 생성하고 count하여 정렬 할 수 있습니다 :

$tags = wp_tag_cloud(array(
    'echo' => false, 
    'orderby' => 'count', 
    'order' => 'DESC' 
)); 

당신은 exclude 매개 변수를 사용하여 특정 태그를 제외 할 수 있습니다 여기에 두 가지 옵션이 있습니다. 글꼴 크기 출력을 사용자 정의하거나 CSS를 사용하여 태그 클라우드 글꼴 크기를 무시할 수도 있습니다.

또 다른 옵션은로 사용할 수 있습니다 get_terms을 사용하는 것입니다

$tags = get_terms(array(
    'taxonomy' => 'post_tag', 
    'orderby' => 'count', 
    'order' => 'DESC', 
)); 

저는 개인적으로 두 번째, get_terms 옵션의 팬이다. wp_tag_cloud과 마찬가지로 exclude 매개 변수를 통해 제외 할 ID 목록을 전달할 수 있습니다.

관련 문제