douchuanghan1344 2015-11-25 11:59
浏览 103

Wordpress重写已有页面的网址

Hi I'm having an issue while rewriting a url like this "news/category_name_here/page_num_here" when I already have a page with the link of "news" it seems to be always considering the first parameter as something else and not the get_query_var I gave it, e.g. category_name_here wouldn't be defined in the call to get_query_var()

Here is my code I was explaining:

function prefix_register_query_var( $vars ) {
    $vars[] = 'cat';
    $vars[] = 'pagenum';

    return $vars;
}
add_filter( 'query_vars', 'prefix_register_query_var' );

function custom_rewrite_rule() {
    add_rewrite_rule('^news/([^/]*)/([^/]*)/?','index.php?page_id=51&cat=$matches[1]&pagenum=$matches[2]','top');
    flush_rewrite_rules();
}
add_action('init', 'custom_rewrite_rule', 10, 0);

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongwei5794 2015-11-25 14:14
    关注

    Seem to have solved it. The issue was that the term "cat" was protected.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?