我使用以下代码创建了一个插件并访问了插件页面:
add_filter('page_template', 'in_page_template4' );
function in_page_template4(){
global $wpdb;
$new_page_title = 'Inventory';
$new_page_title1 = 'inventory-details';
$new_page_title2 = 'spanos-inventory';
$new_page_title3 = 'trade-in-inventory';
$ppid=$_GET['page_id'];
$sql = "SELECT * FROM wp_posts where ID='".$ppid."';";
// $sql = "SELECT * FROM wp_posts where post_name='".$new_page_title."';";
$cnt_post = $wpdb->get_results($sql);
if(count($cnt_post)!=0){ $page_title=$cnt_post[0]->post_name;
if($new_page_title==$page_title){
$page_template = dirname( __FILE__ ) . '/car_inventory.php';
return $page_template;
}elseif($new_page_title1==$page_title){
$page_template = dirname( __FILE__ ) . '/inventory_details.php';
return $page_template;
}
elseif($new_page_title2==$page_title){
$page_template = dirname( __FILE__ ) . '/car_inventory.php';
return $page_template;
}
elseif($new_page_title3==$page_title){
$page_template = dirname( __FILE__ ) . '/car_inventory.php';
return $page_template;
}
}
}
如果我们使用默认的永久链接插件运行良好,但是当我们使用自定义永久链接插件页面时显示页面未找到错误。