Conditional statement for a template file
-
OK so I’m using a template file to have a page on my site that has an image scroller. This requires an external .js file for the code and an “onload” javascript statement to be added to the body tag.
2 issues to overcome…
I have enqued the external .js file the proper way from within functions.php. It would be more ideal to only enqueue it when this template file is used.Also, I only want the “onload=…” to appear when the template file is used. My body tag is inside header.php which is called using get_header() from the template file. How can I ensure this?
One thing I tried was to set a variable that is the “onload=..” like so:
<?php /* Template Name: My special template */ ?> <?php $ScrollerFunc = 'onload="initHIS3()"'; ?> <?php get_header(); ?>And then in header.php:
<body <?php body_class(); ?> <?php if ( isset($ScrollerFunc) ) echo $ScrollerFunc; ?>>But this doesn’t seem to work as it seems the variable $ScrollerFunc is not passed to/available to header.php.
Any ideas?
The topic ‘Conditional statement for a template file’ is closed to new replies.