php in .phtml file not parsing

2019-05-31 22:02发布

I have problem with my boxbilling script. all the phtml files refuse to parse my php codes. I have already confirmed that all handlers and types have been added and working. Its weird, when i create my own .phtml and put my html and php codes inside it works. And it seems the support for boxbilling is dead. I'm planning to get a wordpress menu from my other site to my current one. using these php codes. Thank you all.

<?php 
require( '/home/admin/public_html/wp-load.php' );
$wp->init();
$wp->parse_request();
$wp->query_posts();
$wp->register_globals();
 ?>

<?php 
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('my_mega_menu') ) : ?>
<?php endif; ?>

Code below is part of the .phtml i have marked an area where the code is suppose to go. Thank you

<div class="top-buttons">
                <a id="login-form-link" class="bb-button bb-button-submit" href="{{ 'login'|link }}">{% trans 'Sign in' %}</a>
                <a class="bb-button bb-button-red" href="{{ 'login'|link }}?register=1">{% trans 'Register' %}</a>
            </div>
            {% endblock %}
            {% endif %}
        </div>
        <div class="clear"></div>
    </div>
</div>

<!-- START MENU FROM WORDPRESS -->

<!-- END OF MENU FROM WORDPRESS -->

This code below is was what was displayed on the page.

init(); $wp->parse_request(); $wp->query_posts(); $wp->register_globals(); ?>

UPDATE: I just checked on inspect element my php codes are automatically commented if i use this code only.

<!--?php
require( '/home/admin/public_html/wp-load.php' );
get_header();
?-->

I pasted the code that has already been commented.

标签: wordpress php
1条回答
Root(大扎)
2楼-- · 2019-05-31 22:35

This error is caused by the wordpress .htaccess file, which doesn't "support" .phtml files by default, just add :

AddType application/x-httpd-php .php .phtml

to the .htaccess file and the scripts should work.

P.S. If you are not using the .htaccess file for redirects consider deleting it.

查看更多
登录 后发表回答