Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WP-WP_重写第404页_Php_Wordpress_Templates_Permalinks_Slug - Fatal编程技术网

Php WP-WP_重写第404页

Php WP-WP_重写第404页,php,wordpress,templates,permalinks,slug,Php,Wordpress,Templates,Permalinks,Slug,如果页面使用特定的页面主题,则使用$wp_rewrite更改permalink 结果在首页出现了一个404错误,并且在管理页面中运行良好 //Change permalink to subject function change_permalink_themebasis( $post ) { $template = get_post_meta( $post->ID, '_wp_page_template' ,true ); if ( 'page-branches.php'

如果页面使用特定的页面主题,则使用$wp_rewrite更改permalink

结果在首页出现了一个404错误,并且在管理页面中运行良好

//Change permalink to subject
function change_permalink_themebasis( $post ) {
    $template = get_post_meta( $post->ID, '_wp_page_template' ,true );
    if ( 'page-branches.php' == $template) {
        global $wp_rewrite; 
        $wp_rewrite->page_structure = $wp_rewrite->root . 'branches/%pagename%/'; 
    } elseif ( 'page-modules.php' == $template) {
        global $wp_rewrite; 
        $wp_rewrite->page_structure = $wp_rewrite->root . 'modules/%pagename%/'; 
    } else{
        global $wp_rewrite; 
        $wp_rewrite->page_structure = $wp_rewrite->root . '%pagename%/'; 
    }
}
add_action( 'add_meta_boxes_page', 'change_permalink_themebasis' );
如何解决这个问题?我认为问题在于添加动作类型“添加元框页面”,但我找不到合适的

编辑: Oke发现它的代码如下:

$wp_rewrite->page_structure = $wp_rewrite->root . 'branches/%pagename%/'; 

只需进入设置->永久链接,滚动到底部,然后单击保存更改

在编写指导性答案时,澄清是最重要的-也许可以解释为什么这样做?是的,那不起作用。正常情况下,它确实可以工作,因为在保存时它会重写.htaccess。但这个剧本并不是这样。幸运的是2017年,我在2015年解决了这个问题。。(不记得怎么说)谢谢你的评论。