使用以下代码行调用滑块脚本
if ( is_front_page() && \'slider\' == get_theme_mod( \'featured_content_layout\' ) ) {
wp_enqueue_script( \'twentyfourteen-slider\', get_template_directory_uri() . \'/js/slider.js\', array( \'jquery\' ), \'20131205\', true );
wp_localize_script( \'twentyfourteen-slider\', \'featuredSliderDefaults\', array(
\'prevText\' => __( \'Previous\', \'twentyfourteen\' ),
\'nextText\' => __( \'Next\', \'twentyfourteen\' )
) );
}
您只需复制这些行并将它们添加到子主题中,然后相应地更改您的条件。您的孩子主题中的以下内容应该有效。注意:我相信这里您将js文件保留在父主题中
add_action( \'wp_enqueue_scripts\', \'enqueue_slider_scripts\', 11 );
function enqueue_slider_scripts()
{
if ( is_post_type_archive( \'cpt\' ) // Change \'cpt\' your match your exact cpt
&& \'slider\' == get_theme_mod( \'featured_content_layout\' )
) {
wp_enqueue_script( \'twentyfourteen-slider\', get_template_directory_uri() . \'/js/slider.js\', array( \'jquery\' ), \'20131205\', true );
wp_localize_script( \'twentyfourteen-slider\', \'featuredSliderDefaults\', array(
\'prevText\' => __( \'Previous\', \'twentyfourteen\' ),
\'nextText\' => __( \'Next\', \'twentyfourteen\' )
) );
}
}
编辑只需记住将以下行复制到存档页面以显示滑块
<?php
if ( twentyfourteen_has_featured_posts() )
get_template_part( \'featured-content\' );
?>