Wordpress 不处理外部 php 文件 [英] Wordpress doesnt proces external php file

查看:22
本文介绍了Wordpress 不处理外部 php 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 wordpress 编写我自己的主题,并编写了一个文件,其中包含我所有的模态(twitter bootstrap),它们是 html.我将其添加到主题部分(创建了一个 inc 文件夹)并将其命名为 modals.php.

我通过 php 在我需要模态的页面的任何地方都包含了它.这有效.每当我点击链接时,模态加载.但是,当我开始将 php 添加到模态时,它会中断.我的模态正在加载,但不是从 wordpress 数据库中请求的帖子项目(我用它来使它成为动态内容,因为它是多语言的),它加载了页脚,并破坏了我的网站,这真的让我感到困惑.

我的 modals.php 包含以下内容

<div class="vertical-alignment-helper"><div class="modal-dialog vertical-align-center"><div class="modal-content"><div class="modal-header"><button class="close" type="button" data-dismiss="modal"></button><button class="close" type="button" data-dismiss="modal">x<span class="sr-only">关闭</span></button>&nbsp;<h4 id="myModalLabel" class="modal-title">我的模态弹出窗口

<div class="modal-body modal-list"><div class="modal-content col-md-12"><strong><?php _e(" <!--:en-->是我<!--:--><!--:pl-->To Ja<!--:->");?><p><?php$post = get_post(930);$content = $post->post_content;回声$内容;?></p>

<div class="modal-footer"><button class="btn btn-default" type="button" data-dismiss="modal">关闭</button>

我是否需要告诉我的文件它需要读取特定于 wordpress 的内容,还是需要将我的文件添加到某处才能使其读取?

编辑

因为我只是尝试回显像 test 这样的单词,这很有效,所以我觉得它与 Wordpress 使用的语法有关.有没有办法让 wordpress 知道它应该用 wordpress 语法阅读?

编辑 2

目前,我有多个子页面,所以我只想加载特定页面的特定模式.对于 gdynia,我只想加载那些.我更新了代码,现在有了这个.

else if (is_page ('gdynia')) {get_template_part('modals-gdynia.php');}

然而现在什么都没有发生.以前是这样,

else if (is_page ('gdynia')) {include_once(get_template_directory_uri() .'/modals-gdynia.php');}

解决方案

如果你使用 get_template_part() 你应该没有任何问题.

由于某种原因,您可能包含 modals.php 的方式可能是调用 wp_footer().

所以如果你想使用这个模板,你只需要在你想要的相应文件中调用它.

header.phpsingle.phpfooter.php

是这样的模板默认文件.在其中之一中调用它.

除此之外,我认为它们不应该是一个无法正常工作的问题.

告诉我它是否解决了您的问题,也许可以粘贴 modals.php 被调用的代码上下文以及它是如何被调用的.

I am making an attempt to write my own theme for wordpress and have written a file that contains all my modals (twitter bootstrap), which are html. I added that to the theme section (created an inc folder) and named it modals.php.

I included that via php everywhere in the page where I need the modals. This works. Whenever I click on the link, the modal loads. However, when I start adding php to the modals, it breaks. My modal is being loaded, but instead of the requested post item from the wordpress database (i use that to make it dynamic content, since its multi language), it loads the footer, and breaks my website, which is confusing me really.

my modals.php contains the following

<div id="about" class="modal fade" tabindex="-1">
    <div class="vertical-alignment-helper">
        <div class="modal-dialog vertical-align-center">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" type="button" data-dismiss="modal"></button>
                    <button class="close" type="button" data-dismiss="modal">x<span class="sr-only">Close</span></button>&nbsp;
                    <h4 id="myModalLabel" class="modal-title">
                        My modal popup
                    </h4>
                </div>
                <div class="modal-body modal-list">
                    <div class="modal-content col-md-12">
                        <strong><?php _e(" <!--:en-->It's me<!--:--><!--:pl-->To Ja<!--:-->" ); ?> </strong>
                            <p>
                                <?php
                                    $post = get_post(930); 
                                    $content = $post->post_content;
                                    echo $content;
                                ?>  
                            </p>
                    </div>
                </div>
                <div class="modal-footer"><button class="btn btn-default" type="button" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
</div>

Do I need to tell my file it needs to read wordpress specific, or do I need to add my file somewhere in order to make it read?

edit

As i tried just echo'ing words like test , this works, so I have a feeling it has to do with the syntax Wordpress uses. Is there a way to make wordpress known it should be read with wordpress syntax?

edit 2

At the moment, i am having multiple subpages, so I only want to load certain modals for a certain page. For gdynia, i want to load only those. I updated the code and have now this.

else if (is_page ('gdynia')) {
        get_template_part('modals-gdynia.php'); 
}

Yet nothing happens now. It used to be,

else if (is_page ('gdynia')) {
    include_once(get_template_directory_uri() .'/modals-gdynia.php');
}

解决方案

If you make use of get_template_part() you shoudn't have any issues.

The way you probably included your modals.php was probably calling wp_footer() for some reason.

so if you wanna use this template you just need to call it within the respective file you want it to.

header.php single.php footer.php

Are such template default files. Within one of those just call it.

<?php 
    get_template_part('modals.php'); 

    // Just in case you wanna use a variable from another context into this template. 
    $post_id = 930;
    include(locate_template('modals.php'));
?>

Other than that i don't think their should be an issue it not working.

Tell me if it fixes your issues, maybe paste the code context where the modals.php is being called and how its being called.

这篇关于Wordpress 不处理外部 php 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆