Date Based Category Archives for Wordpress


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function extend_date_archives_flush_rewrite_rules(){
  2. global $wp_rewrite;
  3. $wp_rewrite->flush_rules();
  4. }
  5. add_action('init', 'extend_date_archives_flush_rewrite_rules');
  6.  
  7. function extend_date_archives_add_rewrite_rules($wp_rewrite){
  8. $rules = array();
  9. $structures = array(
  10. $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_date_permastruct(),
  11. $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_month_permastruct(),
  12. $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_year_permastruct(),
  13. );
  14. foreach( $structures as $s ){
  15. $rules += $wp_rewrite->generate_rewrite_rules($s);
  16. }
  17. $wp_rewrite->rules = $rules + $wp_rewrite->rules;
  18. }
  19. add_action('generate_rewrite_rules', 'extend_date_archives_add_rewrite_rules');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.