本文介绍了从wp_get_archives中排除类别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从wp_get_archives中排除类别?我试图在侧边栏中显示月份,但我想排除不是博客条目的帖子.
Is there any way to exclude a category from wp_get_archives? I'm trying to show the months in the sidebar, but I want to exclude the posts that are not blog entries.
$catID = get_cat_id('Projects');
$variable = wp_get_archives('type=monthly&show_post_count=1);
echo $variable;
推荐答案
如果要在主题目录的functions.php中仅包含wp_get_archive函数的特定类别,请使用此选项
Use this if you want to include only specific categories for wp_get_archive function in your functions.php of your theme directory
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;
$includes= '14'; // category id to include
return $x . " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id = '$includes'";
}
这篇关于从wp_get_archives中排除类别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!