2017-07-29 19 views
0

我嘗試開發模板中包含文件的插件。這樣就在這時我的代碼視圖:Wordpress使用插件中的模板文件

/* Add a query var for template select, and and endpoint that sets that query var */ 
add_action('init', 'wpse22543_rewrite_system'); 

function wpse22543_rewrite_system() { 
    global $wp, $wp_rewrite; 
    $wp->add_query_var('template'); 
    add_rewrite_endpoint('kalkulator_leasingowy', EP_ROOT); 
    $wp_rewrite->add_rule( '^/kalkulator_leasingowy/?$', 
     'index.php?template=kalkulator_leasingowy', 'bottom'); 
    $wp_rewrite->flush_rules(); 
} 


/* Handle template redirect according the template being queried. */ 
add_action('template_redirect', 'wpse22543_select_template'); 

function wpse22543_select_template() { 
    global $wp; 
    $template = $wp->query_vars; 

    if (array_key_exists('template', $template) && 
     'kalkulator_leasingowy' == $template['template']) { 
     global $wp_query; 
     $wp_query->set('is_404', false); 

     include(get_stylesheet_directory().'/kalkulator_leasingowy.php'); 
     exit; 
    } 
} 


function prefix_movie_rewrite_rule() { 
    add_rewrite_rule('kalkulator_leasingowy', 'index.php?template=kalkulator_leasingowy', 'top'); 
} 

add_action('init', 'prefix_movie_rewrite_rule'); 

此代碼運行非常精細,包括模板文件,但我的模板(header.php文件和footer.php)默認使用一個可視化的作曲家,當我在使用此代碼頁面視圖這樣的:

enter image description here

enter image description here

視覺作曲家的作品好所有頁面上沒有/ kalkulator_leasingowy。 如何將VC包含到/ kalkulator_leasingowy中?


編輯

kalkulator_leasingowy.php

<?php 
get_header(); 
?> 
<div class="main-wrapper"> 
    <div class="container "> 
     <div class="row"> 

     </div> 
    </div> 
</div> 
<?php get_footer(); ?> 
+0

正如我理解的問題,由於模板正在使用,但輸出不是你所期望的,你的實際問題在於'kalkulator_leasingowy.php'文件,而不是你上面共享的模板代碼。在這種情況下,如果沒有看到模板文件代碼,很難評估爲什麼VC不能正確渲染 - 你能在這裏分享這些代碼嗎? –

+0

Okey,我添加了這個文件。如果你可以請看看它,但是是一個非常簡單的文件。我不知道我可以添加header.php文件,因爲它在themeforest上購買了一個主題。問題很簡單,所有的主題文件都能正常工作,但我從我的插件中添加了「假/虛擬頁面」,並將kalkulator_leasingowy.php添加到主題文件,遺憾的是Visual composer在此頁面上不工作:( – bradley546994

回答

1

我真的不理解,你正在努力使自定義的可視化編輯器的代碼,因爲你的模板文件中沒有任何在它。

但根據您的編輯,它看​​起來像你可能實際上想要使用Child Theme。這些使得向Parent主題添加新的模板文件非常容易,無需編輯任何Parent的代碼,也不需要大部分複雜的代碼。

如果也許你是從其他地方注入視覺作曲家代碼,請確保你正在應用內容過濾器,而不是插入或回顯到前端。

$content = '<div id="my_custom_content">[vc shortcode contents here]</div>'; 
echo apply_filters('the_content', $content); 

這將確保結束內容被過濾和適當渲染。您可能會閱讀this related answer以獲取更多信息。