我找到了一个解决方案,但它确实很难看:hook into 404 routing 交付应交付的页面。代码有点复杂,因为我还需要处理多站点前缀。
theme/404.php
<?php
global $current_blog;
$prefix = $current_blog->path;
$path = $_SERVER[\'REQUEST_URI\'];
$path = preg_replace("!^$prefix!i", "", $path);
$path = preg_replace("!\\?.*$!i", "", $path);
$path = trim($path, \'/\');
$page = get_page_by_path($path);
if (isset($page)) {
$template = get_post_meta($page->ID, \'_wp_page_template\', true);
if (empty($template))
$template = get_page_template();
query_posts("post_type=page&id={$page->ID}");
include($template);
die;
}
?>
...actually handle a 404...
识别出一个页面后,它必须运行
query_posts
再次正确加载所有数据。这远不是理想的解决方案,但至少对我有效。如果有人能提出更好的解决方案,我很乐意用它来代替。