dongzituo5530 2015-05-11 19:41
浏览 22

包括php脚本结果作为纯HTML

I have Wordpress and I want to add its header and footer to a different script template file. The easiest way would be just to copy and paste the html code, but then I will loose all the dynamic changes and so on.

Wordpress gives a way to add header and footer outside with this two files included:

<?
require('wp-load.php');
include('wp-content/themes/theme/header.php');
?>

But this shows me redeclared functions error 0 two functions are with the same name, so that is the conflict. Since I really cannot edit functions names I am looking for a different solution.

So I came up with executing the script on side in different file (test.php), and then add pure html to my header (header.html - file with php parsing)

So I made something like this:

<?
ob_start();
require('wp-load.php');
include('wp-content/themes/theme/header.php');
$header_output = ob_get_contents();
ob_get_clean();
?>

I include it to my header.html like this:

<?
include('test.php');
echo($header_output);
?>

But unfortunately it didn't help - still conflict, so it includes not the executed script (html), but still functions...

I have tested test.php like below just to see if it works:

<?
ob_start();
require_once('wp-load.php');
include_once('wp-content/themes/theme/header.php');
$header_output = ob_get_contents();
ob_get_clean();

echo($header_output);
?>

then for test I saved the $header_output to a text file (using fwrite()) - it worked, pure html! So I think that something is wrong with my includes...

Of course I can generate new content of the text file every time and include it to my header.html, but I think that is not effective.

What can I do to make the wp-load.php not be included do my header.html?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c