我有一个自定义的帖子类型和存档页面。我希望能够使用默认的二十四个主题滑块,以便归档-cpt.php页面调用js并仅显示CPT的滑块。我想我会调用一个函数,但我不知道如何编写脚本,也不知道如何调用它。我知道滑块的位置。这里的任何帮助都是非常感谢的。
发布于 2015-07-13 04:38:04
使用以下代码行调用滑块脚本
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' );
?>https://wordpress.stackexchange.com/questions/194297
复制相似问题