php in .phtml file not parsing - wordpress

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.

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.

Related

What is the url for page-test.php?

I create a file page-test.php in my template directory.
page-test.php
<?php echo "Hello"; ?>
What is the url for this page?
But it's not working...
i want to find the url for display the php file "page-test.php"
You can put this line to create the page template in WordPress
<?php /* Template Name: Example Template */ ?>
and then write your code in this PHP file
<?php echo "Hello"; ?>
After that, assign this page template to the admin area,
Reference: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use
I hope it might be helpful to you!

template management with wordpress (underscore boilerplate)

I am using underscore to develop a wordpress theme.
I have a custom post type name project, thus I have, for instance, this url: http://a.site.local/projects/a-beauty/.
I have in my template-parts/ directory the file content-projects.
$ cat template-parts/content-projects.php
<h1>Project</h1>
When I browse http://a.site.local/projects/a-beauty/, I have my title but also the sidebar and the footer (even if they do not appear in my content-project.php nor in index.php).
Where are those widgets coming from / loaded ?
Add conditions to the header, footer and sidebar.
For whole custom post archive:
<?php if( !is_post_type_archive( 'project' ) ) : ?>
// wrap the code you don't want to show on that archive
<?php endif; ?>
For custom post only:
<?php if( !is_singular( 'project' ) ) : ?>
// wrap the code you don't want to show on the post
<?php endif; ?>
If you want to put the code you WANT to show, remove the '!' before condition.
P.S.
You can put the whole content in a condition, but keep the
</div><!-- #page -->
<?php wp_footer(); ?>
</body>
</html>
otherwise the page will break :)
Please share some more code from your project so we can easy to understand the real problem.

Wordpress Some Content in header file not outputting

I'm developping a Wordpress website, and I need to display conditionnal content in header file, just after opening body tag.
If I call exit(); just after my condition, the code is outputted correctly, so I know condition is working and I'm in the right file. Then I remove the call to exit(); and code is not outputted.
Theme is Divi / Divi-Child, I removed all plugins to be sure (renamed the plugins folder to _plugins), no cache in effect.
I looked at both functions.php and child/functions.php, I don't see any 'after content' functions that would clean/remove the code, although I suspect this is what's happening.
Even the HTML comments are striped ()
</head>
<body <?php body_class(); ?>>
<!-- Advertising -->
<?php
$bool = is_sidebar_active('wallpaper-advertising');
//var_dump($bool);
if($bool){
//exit();
?>
<script>
jQuery(document).ready(function($){
if(jQuery('#ad_habillage').length>0){
jQuery('#adbg, .wallpaper_spacer').show(0);
}else{
jQuery('body').addClass('deactivate_wallpaper');
}
});
</script>
<div id="adbg">
<?php dynamic_sidebar('wallpaper-advertising'); ?>
</div>
<div class="wallpaper_spacer" style="">
<img src="<?= THEME_PATH ?>/media/img/994x112Transparent.gif" border="0" alt="Cliquez ici" title="Cliquez ici">
</div>
<div class="big_wallpaper_wrap_bg">
<div class="big_wallpaper_wrap">
<?php } ?>
<!-- End Advertising -->
Any help is welcome.
I found out using QueryMonitor, it shows templates in use, and header.php was replaced by another file in the theme folder. I moved my code there and it's all fine.

Issue with Timber custom page template for Home page in WordPress

I created page-home-page.twig in my view folder of Timber template. However,
1- If the page home-page set as default wordpress home-page, The template file will not work.
2- If the page home-page set as normal page content, then now the template will be okay.
Can any one advise me where is the issue?
Please view Timber documentation.
I fixed it by doing the following:
1- In my WordPress theme folder /wp-content/themes/my-theme/ I created an Custom Page Template reference to this guide: Custom Page Templates
Using this code:
<?php
/**
* Template Name: Video Template
* Description: A Page Template for Home page Video CMS.
*/
defined('ABSPATH') or die;
use Timber\Timber;
$gantry = Gantry\Framework\Gantry::instance();
$theme = $gantry['theme'];
// We need to render contents of <head> before plugin content gets added.
$context = Timber::get_context();
$context['page_head'] = $theme->render('partials/page_head.html.twig', $context);
$post = Timber::query_post();
$context['post'] = $post;
Timber::render(['page-' . $post->post_name . '.html.twig', 'page-hvideo.twig'], $context);
Where Timber::render(['page-' . $post->post_name . '.html.twig', 'page-hvideo.twig'], $context); pointing us to the new Timber page-hvideo.twig file under theme/view folder.
2- And in my Timber template view folder I added this file page-hvideo.twig with the following code:
{% extends "partials/page.html.twig" %}
{% set twigTemplate = 'single.html.twig' %}
{% set scope = 'single' %}
{% block content %}
<div class="platform-content">
<div class="content-wrapper">
<section class="entry">
{% include ['partials/content-' ~ scope ~ '-home-video.html.twig', 'partials/content-home-video.html.twig'] %}
</section>
</div> <!-- /content-wrapper -->
</div>
{% endblock %}
Where {% include ['partials/content-' ~ scope ~ '-home-video.html.twig', 'partials/content-home-video.html.twig'] %} Will manage the home page custom template from view/partials folder under Timber theme folder as normal.
I hope this will help anyone else.
Thank you so much for everything you provided here.
EDITED:
Please be sure after you add your Home Page custom page template to select it from your post editing screen in WordPress under Page Attributes section.

Comment in .blade.php template

I am new in blade template. How i comment here?
PHP i can comment like this
<?php // echo $games;?>
Laravel Blade
{{ $game }}
In blade syntax, a comment starts with {{-- and ends with --}}
{{-- this is a comment --}}
But to comment out multiple lines, use standard PHP block comments instead, like:
<?php /*
#if ($condition)
{{ HTML::form("foo") }};
#endif
*/ ?>
And never nest Blade and/or PHP code inside of Blade comments.
See also stackoverflow.com/Why Blade comment causes page to crash?

Resources