【发布时间】:2015-02-10 08:05:57
【问题描述】:
我正在尝试向 wordpress 子主题页面添加一个简单的滑块,但无法正常工作。
滑块 html(header.php):
$args = array(
'post_type' => 'slide'
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<div class="flexslider"><ul class="slides">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
//echo '<li><a href="#">' . the_post_thumbnail() . '</a> </li>';//this was wrong
echo '<li><a href="#">' . get_the_post_thumbnail() . '</a> </li>';//this is right
}
echo '</ul></div>';
} else {
// no posts found
}
wp_reset_postdata();
脚本(functions.php)
function my_scripts() {
wp_register_script( 'flexslider', get_stylesheet_directory_uri() . '/flexslider/jquery.flexslider.js', array( 'jquery' ), '1.0', true );
wp_register_script( 'slide', get_stylesheet_directory_uri() . '/flexslider/flexscript.js', array( 'jquery' ), '1.0', true );
if ( is_front_page() ) {
wp_enqueue_script( 'flexslider' );
}
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
jquery.flexislider.js 是必需的js文件。 flexiscript.js 包含以下代码:
jQuery(document).ready(function() {
jQuery('.flexslider').flexslider();
});
我的标题中也包含 css
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/flexslider/flexslider.css" type="text/css">
【问题讨论】:
-
你有任何控制台错误..??
-
只是这个:
The "fb-root" div has not been created, auto-creating我怀疑这与滑块或 jquery 有什么关系