0

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

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

  }
}

如果我们使用默认的永久链接插件运行良好,但是当我们使用自定义永久链接插件页面时显示页面未找到错误

4

1 回答 1

0

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

dirname( __FILE__ )

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

plugin_url('car_inventory.php');
于 2013-03-04T14:41:40.987 回答