Hi,
I'd like to conditionally load javascript and css in the footer of my theme (via common/footer.php), but can't seem to get the PHP to work. My problem is that everything loads on all the pages, instead of the particular ones that I want. Here's an example of what I have:
<?php if ($bodyclass=='show-items'); { ?>
<script src="/themes/my-theme/rest/of/path/jquery-plugin.js"></script>
<script>
example javascript
</script>
<?php } ?>
Any help would be much appreciated!
Haven't tested this, but my guess is that the way you are setting up the if is kind of a mix of syntaxes.
This might work better:
<?php if ($bodyclass=='show-items'): ?>
<script src="/themes/my-theme/rest/of/path/jquery-plugin.js"></script>
<script>
example javascript
</script>
<?php endif; ?>
Hmm. That works really well in the header, but not the footer. Any idea why? It's not too big of a problem if I load that stuff in the header, instead of the footer.
Thanks for the assistance, by the way :)
My first guess would be that there's a problem with where it is being added -- maybe something is turning out wrong in the html that's generated. Could you post up your entire footer.php file, with where you are adding in the code?
This is all I have and I'm developing locally, so there's currently no where to look at this on the web.
</div>
</div>
<footer class="row">
<div class="twelve columns">
<?php echo get_theme_option('Footer Text'); ?>
<p>© <? echo date("Y"); ?>, My Site</p>
<p><?php echo __('Proudly powered by Omeka.'); ?></p>
</div>
<?php plugin_footer(); ?>
</footer>
</div>
<?php if ($bodyclass=='show-items'):?>
<script src="/themes/my-theme/javascripts/jquery-plugin.js"></script>
<script>
javascript
</script>
<?php endif;?>
</body>
</html>
Again, thanks for the help. If we can't get this resolved, it's no big deal. I still have lots of time to develop the theme.
Nothing quite leaps out to me as an obvious culprit, though that closing </div> after the footer element seems a little surprising.