wordpress上的自定义永久链接问题

时间:2013-03-04 10:58:57

标签: php wordpress

我使用以下代码创建了一个插件并访问了插件页面:

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;
      }

  }
}

如果我们使用默认永久链接插件工作得很好但是当我们使用自定义永久链接插件页面显示页面未找到错误

1 个答案:

答案 0 :(得分:0)

在尝试回答您的问题时,我会说您想要更改此部分

dirname( __FILE__ )

到你想要的实际目录,如果你想要插件目录

plugin_url('car_inventory.php');