• 注册
  • 备忘录 备忘录 关注:1 内容:5

    话题中文转换为ID WordPress主题通用

  • 查看作者
  • 打赏作者
  • 当前位置: 投稿客 > 备忘录 > 正文
    • 备忘录
    • 副高
      管理员

      代码放在模板函数 (functions.php)

      代码添加后一定要重新保存一下固定链接

      /* 标签以id方式展示*/
        
      add_action('generate_rewrite_rules','tag_rewrite_rules');
        
      add_filter('term_link','tag_term_link',10,3);
        
      add_action('query_vars', 'tag_query_vars');
        
      function tag_rewrite_rules($wp_rewrite){
        
      $new_rules = array(
        
      'tag/(\d+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
        
      'tag/(\d+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
        
      'tag/(\d+)/embed/?$' => 'index.php?tag_id=$matches[1]&embed=true',
        
      'tag/(\d+)/page/(\d+)/?$' => 'index.php?tag_id=$matches[1]&paged=$matches[2]',
        
      'tag/(\d+)/?$' => 'index.php?tag_id=$matches[1]',
        
      );
        
      $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
        
      }
        
      function tag_term_link($link,$term,$taxonomy){
        
      if($taxonomy=='post_tag'){
        
      return home_url('/tag/'.$term->term_id);
        
      }
        
      return $link;
        
      }
        
      function tag_query_vars($public_query_vars){
        
      $public_query_vars[] = 'tag_id';
        
      return $public_query_vars;
        
      }

      请登录之后再进行评论

      登录
    • 投稿
    • 任务
    • 风格偏好设置
    • 帖子间隔 侧栏位置: