2016-10-07 12 views
0

我想包括表为WordPress的页面。 该表包含一些php代码,所以想用简码尝试这样做。WP PHP包括与简码始终在顶部

我不想让这个页面模板,因为我想轻松地编辑文本(在WP页面编辑器)的上面和下面的表中包含的。

的问题是,如果我有包含表的PHP文件,该表将永远是在页面的顶部,而不是文章的中间。我怎样才能解决这个问题?

function include_scams_page_template() 
{ 
    $path = get_template_directory() . '/templates/scams.php'; 
    $output = include $path; 
    return $output ; 
} 
add_shortcode ('include_scams_page_template' , 'include_scams_page_template'); 

回答

1

试试这个:

function include_scams_page_template() 
{ 
    $path = get_template_directory() . '/templates/scams.php'; 
    ob_start(); 
    include $path; 
    $output = ob_get_clean(); 
    return $output ; 
} 
add_shortcode ('include_scams_page_template' , 'include_scams_page_template'); 

说明

我猜你的代码scams.php产生输出来早。 ob_start()转为输出缓冲,ob_get_clean()结束并返回缓冲区内容。

+0

WORKED !!!!!!非常感谢。如果没有帮助,我绝不会猜到它。 – user1159265

+0

欢迎你。当一切正常时,请考虑接受我的回答:) –