我有一个数据库表与一些用户生成的内容。每个内容元素都可以通过/ my-url/project/the-projects-name获得。这些项目是没有WordPress的帖子。我创建了一个索引脚本,在重定向到这样的URL时被调用。该脚本然后提取项目名称,将其放入一个变量并包含一个页面模板。 我的页面和项目数据显示的很好,但wordpress会为请求的网站引发404状态,并将标题设置为“Not Found!”。我怎样才能伪造wordpress输出?自己的重写规则为WordPress的特殊网址
我的htaccess其重定向到我的指数projects.php脚本:
RewriteCond %{REQUEST_URI} ^/my-url/project/(.*)
RewriteRule . /index-project.php [L]
我的指数project.php:
ob_start();
define('WP_USE_THEMES', true);
$path = explode('/', $_SERVER['REQUEST_URI']);
while(empty($path[0]))
array_shift($path);
while(empty($path[count($path)-1]))
array_pop ($path);
if(count($path) >= 3 && !empty($path[2])) {
$postFound = false; // use this param to define if requested post was found in DB
$post_name = $path[2]; // get the post name from url
$args = parse_url($post_name);
$slug = $args['path']; // extract the post slug from post name
if(!empty($slug)) {
$wp_did_header = true;
$_GET['page_id'] = SOME_ID_OF_MY_WP_PAGE;
$_GET['main_page'] = 'page-project';
require_once(dirname(__FILE__) . '/wp-load.php');
wp();
include('./wp-content/themes/my-theme/page-project.php');
}
}
WordPress的仍然抛出404页装入正确,内容是“重定向”我的指数project.php但WP仍然返回404头到浏览器... – Denis 2012-02-22 08:26:15
我想有一些东西必须添加到index-project.php脚本,以告诉WordPress不会搜索url所请求的页面/帖子 – Denis 2012-02-22 08:29:26