我有一个名为“博客”的cpt,现在我想列出所有为该cpt做出贡献的作者。此外,我还想列出所有按月份分组的博客帖子(来自“blog”cpt),就像wp\\u get\\u archives()一样。
作者。我尝试使用wp\\u list\\u authors,但它只列出常规帖子的作者,而不是cpt的作者。我只想列出“blog”cpt的作者。怎么办?
每月档案。我尝试使用wp\\u list\\u archives(),遵循Bainernet的指示(此处:Get monthly archives for custom post type) 上面写着“monthname年”,看起来很棒。但是,创建的permalinks如下所示:www.example。com/2011/10。。。而那将一事无成!我得到一个404错误。所有“博客”cpt帖子都位于www.example下。com/blog,我希望日期存档url也包括/blog所以也许这只是一个重写的东西,但我确实修复了它只需手动键入www.example。com/blog/2011/10也只能让我进入404错误页面。
希望你能帮助我!
更新1我成功地将URL重写到归档文件中,所以现在它们看起来像这样:www.example。com/blog/2011/10
这是我用于重写的代码:
add_rewrite_tag(\'%blog-date%\',\'([\\d]{4}-[\\d]{2}-[\\d]{2})\'); add_action( \'init\', \'blog_rewrites\' ); function blog_rewrites() { add_rewrite_rule( "blog/day/([\\d]{4}-[\\d]{2}-[\\d]{2})/?$", \'index.php?post_type=blog&blog-date=$matches[1]\', \'top\' ); } add_filter( \'query_vars\', \'blog_vars\' ); function blog_vars ( $vars ) { $vars[] = \'blog-date\'; return $vars; }
应用下面@Bainternet回复中的代码,我可以让我的作者列表正常运行,但我的每月档案链接上仍然有404。但url似乎是正确的:www.example。com/blogg/2011/10这是我函数中的代码。php当前:
add_filter(\'get_archives_link\', \'blog_archive_links\');
function blog_archive_links($html){
$home_url = home_url();
$home_url_with_blog = $home_url .\'/blogg\';
return str_replace($home_url,$home_url_with_blog,$html);
}
//to match http://www.example.com/blog/2011/12/1/ use
add_rewrite_rule(\'^blogg/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$\',\'index.php?post_type=blogg&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]\',\'top\');
//to match http://www.example.com/blog/2011/12/1/page/2 use
add_rewrite_rule(\'^blogg/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$\',\'index.php?post_type=blogg&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&page=$matches[4]\',\'top\');
//to match http://www.example.com/blog/2011/12/ use
add_rewrite_rule(\'^blogg/([0-9]{4})/([0-9]{1,2})/(?$\',\'index.php?post_type=blogg&year=$matches[1]&monthnum=$matches[2]\',\'top\');
//to match http://www.example.com/blog/2011/12/page/2 use
add_rewrite_rule(\'^blogg/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$\',\'index.php?post_type=blogg&year=$matches[1]&monthnum=$matches[2]&page=$matches[3]\',\'top\');
function Cpt_getarchives_where_filter( $where , $r ) {
$post_type = \'blogg\';
return str_replace( "post_type = \'post\'" , "post_type = \'$post_type\'" , $where );
}
这是我侧边栏中的代码。php:add_filter( \'getarchives_where\' , \'Cpt_getarchives_where_filter\' , 10 , 2 );
wp_get_archives();
remove_filter(\'getarchives_where\' , \'Cpt_getarchives_where_filter\' , 10 );
正如你所看到的,我的cpt不叫“blog”,它实际上叫“blogg”,这是瑞典语的拼写,但不重要。此外,我没有使用任何插件来让cpt归档工作,我只是创建了一个名为archive blogg的文件。php并使用一个名为“Custom Post permalinks”的插件将“blogg”cpt中的博客帖子的永久链接设置为“/blogg”,该插件似乎已经不存在了。它似乎在其他方面都做得很好,但我可以尝试用函数中的一些代码替换该插件。php。除此之外,还有什么其他可以测试的东西可以让它工作吗?