duanhu2414 2013-11-14 23:32
浏览 34

在Wordpress模板中包含PHP文件

As of right now I have this code in one of my templates on my Wordpress theme.

// blah blah

        <div class="content">

            <?php include_once( 'http://www.website.com/new/file.php?variable=1' ); ?>

        </div>

// blah blah

Now, it will load everything in this template except this php include! It will load the sidebar which is included above the /* blah blah */ and it will load the footer, navigation, etc.

When I Inspect Element on Google Chrome it shows this:

<div class="content">

       (it's empty)

</div>

Please help me if you know what I'm doing wrong! Thank you!

  • 写回答

1条回答 默认 最新

  • duanjia9577 2013-11-14 23:38
    关注

    include and require don't take URLs. They take server filepaths. Try this:

    <?php include_once(ABSPATH.'/new/file.php'); ?>
    

    EDIT: Forgot to mention that query strings cannot be included in filepaths. If a query string is necessary for proper loading, consider loading the page with all necessary query variables in your current URL, loading the part using an iframe, or using file_get_contents()

    Iframe:

    <iframe src="http://www.website.com/new/file.php?variable=1"></iframe>
    

    file_get_contents()

    <?php echo file_get_contents('http://www.website.com/new/file.php?variable=1'); ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?