2015-10-26 19 views
0

這是必需的,像/ catalog/category/subcategory/my_mark /這個自定義url顯示的這個子類別的產品(爲my_mark presense過濾)完全如同/ catalog/category/subcategory /。 我寫了一個插件,並試圖通過在功能改變$ wp_query變量作爲條件的改變的邏輯:woocommerce自定義過濾產品頁面製作,或如何正確地修補woocommerce中的wp_query?

load_template, get_header 

,但是,它仍然是不一樣的模板順序,所以問題是如何(和/或地方)更改$ wp_query只是爲了顯示正確的模板順序的結果,因爲它會在正常的子類模板視圖?

回答

0

通過過濾template_include函數做到了,之前調試過使用了正確的模板文件。這裏的代碼,也許它會幫助別人:

add_filter('template_include', 'seo_includer'); 
function seo_includer($args) { 

     global $wp_query; 

     if(<my_condition>) 
     { 
      if (true) { 
       status_header(200); 
       $wp_query->is_404=false; 
      } 

      $args = array(
       'posts_per_page' => 777, 
       'product_cat' => $category['slug'], 
       'post_type' => 'product', 
       'orderby' => 'meta_value_num', 
      ); 
      $wp_query = new WP_Query($args); 
      return ABSPATH.'wp-content/themes/<mytheme>/woocommerce/taxonomy-product_cat.php'; 
     } 
     return $args; 
}