在Wordpress中按年获得月度帖子
我希望得到一份2014年发布的月份列表。例如: 2014年 -一月 -二月 我还需要在那里的“活跃”类的功能,当我在那个月 我已经尝试了一百万个插件,并在没有运气的情况下乱搞了归档功能在Wordpress中按年获得月度帖子,wordpress,archive,posts,Wordpress,Archive,Posts,我希望得到一份2014年发布的月份列表。例如: 2014年 -一月 -二月 我还需要在那里的“活跃”类的功能,当我在那个月 我已经尝试了一百万个插件,并在没有运气的情况下乱搞了归档功能 function my_custom_post_type_archive_where($where,$args){ $post_type = isset($args['post_type']) ? $args['post_type'] : 'post'; $where = "WHE
function my_custom_post_type_archive_where($where,$args){
$post_type = isset($args['post_type']) ? $args['post_type'] : 'post';
$where = "WHERE post_type = '$post_type' AND post_status = 'publish'";
return $where;
}
那么就称之为:
add_filter( 'getarchives_where','my_custom_post_type_archive_where',10,2);
每当您想按自定义帖子类型显示存档时,只需传递帖子类型参数:
$args = array(
'post_type' => 'your_post_type',
'type' => 'monthly',
'echo' => 0
);
echo '<ul>'.wp_get_archives($args).'</ul>';
$args=array(
“发布类型”=>“您的发布类型”,
'类型'=>'每月',
“echo”=>0
);
回显“”.wp_get_归档($args)。“
”;
我最终使用分类法来实现这一点,我更希望它自动显示这一点,但目前看来这似乎是最好的折衷方案。不过,我会尝试一下San Jay的选择。谢谢你,那么我应该把functions.php中的内容和category.php侧边栏中的内容放在哪里呢?这是用于普通帖子,而不是自定义帖子类型:)如果您使用for post,则必须调用:$args=array('type'=>'monthly','echo'=>0);回显“- ”.wp_get_归档($args)。“