2014-07-17 25 views
0

我想表明我的wordpress網站的存檔結構我怎樣才能爲特定類別只在我的wordpress網站自定義歸檔的名單

-2014(15) 
--Jan(2) 
--Feb(5) 
----Blog Title1 
----Blog Title2 
----Blog Title3 
----Blog Title4 
----Blog Title5 

默認爲顯示所有的帖子出現在我的網站。

但我只想列出只屬於「category =>'blog-post'」的帖子。

我已嘗試使用-<?php get_archives(); ?>,但它會顯示我網站上顯示的所有帖子的列表。

+0

http://wordpress.stackexchange.com/questions/95776/how-we-display-archives-for-specific-categories – Dipak

+0

我得到了我的答案在這個鏈接謝謝你! – Dipak

回答

0

試試這個:

add_filter('getarchives_where', 'get_archives_where', 10, 2); 
add_filter('getarchives_join', 'get_archives_join', 10, 2); 

wp_get_archives(array('type' => 'monthly')); //put your parameters 

remove_filter('getarchives_where', 'get_archives_where'); 
remove_filter('getarchives_join', 'get_archives_join'); 


function get_archives_where($where, $r){ 

    global $wpdb; 

    $where .= " AND ". $wpdb->prefix. "terms.slug = 'blog-post' AND ". $wpdb->prefix. "term_taxonomy.taxonomy = 'category'"; 

    return $where; 
} 

function get_archives_join($join, $r){ 

    global $wpdb; 

    $join = "inner join ". $wpdb->prefix . "term_relationships on ". $wpdb->prefix . "posts.ID = ". $wpdb->prefix . "term_relationships.object_id inner join ". $wpdb->prefix . "term_taxonomy on ". $wpdb->prefix . "term_relationships.term_taxonomy_id = ". $wpdb->prefix . "term_taxonomy.term_taxonomy_id inner join ". $wpdb->prefix . "terms on ". $wpdb->prefix . "term_taxonomy.term_id = ". $wpdb->prefix . "terms.term_id"; 

    return $join; 
} 

https://wordpress.stackexchange.com/questions/95776/how-we-display-archives-for-specific-categories作品。我剛剛以更合適的方式呈現了它。

我還發現這個http://wordpress.org/plugins/wp-category-archive的部件。這也可能有助於一些(但是,這個插件是非常舊的)

+0

這將是一個選項https://wordpress.org/plugins/jquery-archive-list-widget/ – Dipak

相關問題