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>
<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.
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.