【发布时间】:2012-05-06 09:05:28
【问题描述】:
这真的让我发疯了一段时间,所以我希望有人能提供帮助。我正在尝试使用wp_get_archives() 显示指向年度档案的链接列表显示当前类别中的帖子。
重要的是,我正在尝试不使用插件,只使用函数文件甚至WP_Query 循环。
示例
想象一下,我有以下所有类别的帖子:
展览(父)
--当前(子)
--过去(孩子)
艺术品(父)
--最近(儿童)
--精选(儿童)
--老(孩子)
我想要做的基本上是这样的:
/* Get current Cat ID */
function getCurrentCatID() {
global $wp_query;
if(is_category() || is_single()){
$cat_ID = get_query_var('cat');
}
return $cat_ID;
}
$currentCat = getCurrentCatID();
wp_get_archives('type=yearly&cat=$currentCat'); // But, you can't filter this by category it seems
所以,如果我查看“展览”类别(使用 category.php),wp_get_archives() 将显示 2012、2011、2010 等的链接。
当我点击 2011 年时,我会看到属于“展览”类别的帖子,并且它是子类别(也很重要)。
我发现这篇文章可能有答案:Exclude Category From wp_get_archives?
但我不知道如何使用帖子中提到的过滤器中正在查看的当前类别,也不知道如何向其中添加多个类别(即父类别加上它的子类别)。
非常感谢任何帮助。
奥苏
【问题讨论】:
标签: wordpress function filter archive