2014-11-18 5 views
0

내 WordPress 블로그는 현재 한 달 단위로 아카이브를 보여줍니다. 이처럼 : 2014특정 형식으로 표시하려면 WordPress 보관함이 필요합니다.

11월
년 10 월 2014
년 9 월 2014
년 8 월 2014
년 7 월 2014
년 6 월 2014 2014

.....
하고 그렇게

I에 현재 연도가 모든 달을 표시하는 방식으로 표시해야하지만, 그 전년도에는 "연도"만 표시됩니다. 이런 식으로 뭔가 :

년 11 월 2014
년 10 월 2014
년 9 월 2014
...
... 2014
2월


1월

누군가 나를 안내 할 수 있습니까? 내 블로그의 사이드 바에서 현재 코드는 다음과 같이 간다 : 당신은 분명히 문제를 일으키는 wp_get_archives('type=monthly') 이외의 아무것도 사용하지하고

<?php /* If this is a category archive */ if (is_category(0) || in_category(0)) { ?> 
<?php ?><ul> 
<?php 
$querystr = "SELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month' , count(ID) as posts FROM $wpdb->posts 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) WHERE $wpdb->term_taxonomy.term_id != 12 AND $wpdb->term_taxonomy.parent != 12 AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id =8 AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC"; 

$years = $wpdb->get_results($querystr); 

foreach ((array) $years as $year) { 
    $url = get_month_link($year->year, $year->month); 
    $url = $url.'?cat=8'; 
    $date = mysql2date('F o', $year->year.'-'.$year->month, $translate = true); 
    echo get_archives_link($url, $date, 'html','<li>','</li>'); 
} 
?> 
</ul><?php 

?> 

<?php } else { ?> 
      <?php wp_get_archives('type=monthly');?> 

<?php } ?> 



       </ul> 






         </div> 
          <div class="archive-bottom"></div> 
       <!-- <div class="clear"></div>--> 
<?php } ?>     




</div> 

답변

0

합니다. wp_get_archives() docs in the Codex을 살펴보십시오.

다음은 샘플 솔루션이지만 약간의 작업이 필요할 것입니다 (게시물에 표시된 것처럼 매월 게시한다고 가정 함). 그것은 테스트되지 않았으므로, 당신의 책임하에 사용하십시오.

// Get the current month number 
$current_month = date('n'); 

// Show the archives for the current year, by month, 
// by limiting the returned archives to the current month number 
$args = array(
    'limit' => $current_month 
); 
wp_get_archives($args); 


// Awesome, now let's get the previous years, but leave off this year 
$yearly_archives = wp_get_archives('type=yearly&echo=0'); 
// Split the returned archives at this year... 
$old_archives = explode('</li>', $yearly_archives, 2); 
// And only echo list items that don't include this year. 
echo $old_archives[1]; 
+0

훌륭한 작품! 엄청 고마워. 한 가지만 더 (나는 불행하게도 많은 코더가 아니다). "2012 년 게시물"과 같은 것을 읽는 아카이브가 필요하다면 "2012"연도가 표시되는 대신에? –