2014-12-12 3 views
0

그래서이 슬라이더를 제어하려고하므로 플러그인을 사용하고 싶지 않습니다. 스타일 및 js 파일을 사용하지 않는 문제가 있습니다. 나는 함수 파일을 통해 그들을 호출하고 파일은 CSS와 JS 폴더에 테마 내에 위치하고 있습니다.wordpress 내의 BXSlider

다음은 jquery로 js를 호출하는 함수입니다.

 <ul class="bxslider"> 
    <li><img src="/images/pic1.jpg" /></li> 
    <li><img src="/images/pic2.jpg" /></li> 
    <li><img src="/images/pic3.jpg" /></li> 
    <li><img src="/images/pic4.jpg" /></li> 
</ul> 





    <script> 
jQuery(document).ready(function() { 
jQuery('.bxslider').bxSlider({ 
    adaptiveHeight: true, 
    mode: 'horizontal', 
    captions: true, 
    auto: true, 
    useCSS: true, 
    easing: 'ease-in', 
    pager: false 
}); 
}); 
</script> 

: 마찬가지로 여기

function theme_name_scripts() { 
    wp_enqueue_script('bxslider', get_template_directory_uri() . '/js/jquery.bxslider.js', array(), '1.8.2', true); 
} 

add_action('wp_enqueue_scripts', 'theme_scripts'); 

는 I는 다음과 같이 전면 page.php 직접 슬라이더를 배치 한 CSS (모두 bxslider 제외 작동)

function theme_styles() { 
    wp_enqueue_style('normalize', get_template_directory_uri() . '/css/normalize.css'); 
    wp_enqueue_style('grid', get_template_directory_uri() . '/css/grid.css'); 
    wp_enqueue_style('main', get_template_directory_uri() . '/style.css'); 
    wp_enqueue_style('social', get_template_directory_uri() . '/css/webfonts/ss-social.css'); 
    wp_enqueue_style('social', get_template_directory_uri() . '/css/jquery.bxslider.css'); 

} 

add_action('wp_enqueue_scripts', 'theme_styles'); 

인 하드 코딩 된 이미지 대신 게시물을 표시하고 싶습니다. 여기에 PHP를 사용하고 있습니다.

<?php 
$content = '<ul class="bxslider">'; 
$loop = new WP_Query(array('post_type' => 'your_post_type', 'posts_per_page' => 10, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC')); 
    while ($loop->have_posts()) : $loop->the_post(); 
     $thumb_id = get_post_thumbnail_id(); 
     $thumb_url = wp_get_attachment_image_src($thumb_id,'full', true); 
     $content .= '<li><a href="'; 
     $content .= get_permalink(); 
     $content .= '"><img src="'; 
     $content .= $thumb_url[0]; 
     $content .= '" alt="'; 
     $content .= get_the_title(); 
     $content .= '" /></a></li>'; 
    endwhile; 
$content .= '</ul>'; 
echo $content; 
?> 

나는 여기서 눈에 띄는 것이 보이지 않는지보기 만하면됩니까?

+0

어떤 오류가 있습니까? PHP 또는 JavaScript 오류? front-page.php는 무엇입니까? – Dharmang

+0

front-page.php는 WordPress의 방문 페이지이며, WordPress 템플릿 계층 구조의 일부입니다. PHP에서는 오류가 없지만 BXslider의 Uncaught ReferenceError에 대한 콘솔 로그에 오류가 있습니다. jQuery가 정의되지 않았습니다 (색인) : 164 (익명 함수) '이 줄 ...'jQuery (문서). 준비가되었습니다. (function() { ' – user3328557

답변

1

bxslider js가 jQuery에 포함되기 시작한 것 같습니다.

이 의존성 문제를 해결하기 위해, 워드 프레스 wp_enqueue_script 함수는 매개 변수는 $ deps라고, 그래서 다음과 같은 코드를 시도했습니다

function theme_name_scripts() { 
    wp_enqueue_script('bxslider', get_template_directory_uri() . '/js/jquery.bxslider.js', array('jquery'), '1.8.2', true); 
} 

add_action('wp_enqueue_scripts', 'theme_scripts'); 

더 많은 정보를 원하시면 참조 : http://codex.wordpress.org/Function_Reference/wp_enqueue_script

+0

이상한 일은 테스트 할 때 JQuery를 헤더 파일에 호출했지만 아직 공을 안 ... – user3328557

+0

html 소스를 살펴보면 js 포함의 순서를 확인할 수 있습니까? – Dharmang

+0

소스에서 JQuery는 모든 스타일 시트를 뒤따라 오지만 위의 함수는 bxslider를 호출하지 않습니다. JQuery는 수동으로 heade에 포함하고 함수를 통해서는 아니지만 manul을 제거했지만 JQuery는 표시하지 않습니다. 포함되어 있습니다 – user3328557