is_page
检测到弹头时工作正常。然而is_page_template
函数不是,所以我尝试了global $template
我也是,但这也不行。如何解决此问题?
我想加载页面的JS文件template-parts/content.php
function software_enqueue() {
if ( is_page( \'software\' ) ) {
wp_enqueue_script(\'sticky-kit.min.js\', get_template_directory_uri().\'/inc/assets/js/sticky-kit.min.js\', false ,\'1.0\', \'all\' );
}
global $template;
if ( basename( $template ) === \'template-parts/content.php\' ) {
wp_enqueue_script(\'sticky-kit.min.js\', get_template_directory_uri().\'/inc/assets/js/sticky-kit.min.js\', false ,\'1.0\', \'all\' );
}
}
add_action( \'wp_enqueue_scripts\', \'software_enqueue\' );
顺便说一句,我也尝试使用下面的代码调用该文件(fullwidth.php),但没有成功:
if ( is_page_template(\'fullwidth.php\') ) {
wp_enqueue_script(\'sticky-kit.min.js\', get_template_directory_uri().\'/inc/assets/js/sticky-kit.min.js\', false ,\'1.0\', \'all\' );
}
fullwidth.php
<?php
/**
* Template Name: Full Width
*/
get_header(); ?>
<section id="primary" class="content-area content-fullwidth">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( \'template-parts/content\', \'page\' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</section><!-- #primary -->
<?php
get_footer();