簡體   English   中英

自定義永久鏈接問題在WordPress上

[英]custom permalink issue on 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;
      }

  }
}

如果我們使用默認的永久鏈接插件可以很好地工作,但是當我們使用自定義的永久鏈接插件頁面時,顯示頁面未找到錯誤

在嘗試回答您的問題時,我會說您想更改此部分

dirname( __FILE__ )

到想要的實際目錄,如果您想要插件目錄

plugin_url('car_inventory.php');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM