2016-02-29 69 views
1

我想讓wordpress爲wordpress頁面加載一個特定的靜態php文件(不是頁面模板)。加載一個特定的PHP頁面

例如,對於我想加載已經完成的contact.php的聯繫人頁面。

我嘗試添加在functions.php的是這樣的:

if(is_page('careers')){ 
    get_page('careers.php'); 
} 

function get_pages() { 
    if(is_page('careers')) { 
      return get_template_uri() . '/careers.php'; 
    } 
} 

我缺少什麼?

編輯:我設法加載頁面,將它們重命名爲page-careers.php,page-contact.php等。 我試過你的解決方案,但我沒有成功。

回答

1

獲取模板部分通常是用於檢索的模板文件,比如你正在嘗試做的。查看更多在這裏:https://developer.wordpress.org/reference/functions/get_template_part/

因此,例如在你的代碼上面,如果你有一個名爲contact.php在你的主題文件夾中的文件,你想有,你可以使用下面的代碼:

get_template_part('contact'); 
3

嘗試此包括PHP文件

<?php include(ABSPATH . "banner.php"); ?> 

並獲得另一頁內容

$my_id = 5369; 
$post_id_5369 = get_post($my_id); 
$content = $post_id_5369->post_content; 
$content = apply_filters('the_content', $content); 
$content = str_replace(']]>', ']]>', $content); 
echo $content; 
相關問題