2013-05-22 1 views
0

Wordpress 웹 사이트에 눈 가을 효과를 만드는 플러그인을 개발하려고합니다. 나는 그것이 작동 내 테마에서이 jQuery 코드를 복사 할 때WP 테마 코드를 독립 실행 형 플러그인으로 변환

<?php 
/* 
Plugin Name: tuhin 
Plugin URI: no plugin uri 
Description: This plugin will add a Simple & lightweight responsive slider. 
Author: tuhin 
Author URI: no author uri 
Version: 1.0 
*/ 
/* Launch the plugin. */ 
add_action('plugins_loaded', 'wp_snowfall_plugins_loaded'); 

/* Initializes the plugin and it's features. */ 
function wp_snowfall_plugins_loaded() { 
    /* Set constant path to the members plugin directory. */ 
    define('WP_SNOWFALL_DIR', plugin_dir_path(__FILE__)); 

    /* Set constant path to the members plugin directory. */ 
    define('WP_SNOWFALL_URL', plugin_dir_url(__FILE__)); 

    /* Loads the snowfall. */ 
    add_action('wp_head', 'wp_snowfall_source'); 
    add_action('wp_head', 'wp_snowfall_effect'); 
} 


function wp_snowfall_source() { 
    wp_enqueue_script('jquery.js'); 
    wp_enqueue_script('snowfall', WP_SNOWFALL_URL.'snow.min.jquery.js'); 
} 

function wp_snowfall_effect() { ?> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    $.fn.snow(); 
}); 
</script> 
<?php 
} 
?> 

,하지만 난 플러그인으로 변환 할 때 작동하지 않습니다 : 내 코드는 다음과 같습니다. 그게 뭐가 잘못 됐어?

+0

당신이 설치 한 워드 프레스의 관리자 패널을 통해 활성화 할 플러그인을 만들 때? – chrislondon

+0

그래, 나는 플러그인을 활성화했다. –

+0

당신은 다음을 사용 해본 적이 있습니까 :'wp_enqueue_script ('snowfall', WP_SNOWFALL_URL.'snow.min.jquery.js ', array ('jquery ')); 어떤 콘솔/PHP 로그 오류가 있습니까? – Joe

답변

0

시도 : 당신은 잘못 jQuery를 사용하는 add_action('init', 'wp_snowfall_plugins_loaded'); 대신

+0

답장을위한 Thnx입니다. 하지만 불행히도 코드가 작동하지 않습니다. –

0

.

그리고, 당신의 jQuery를 명령 시동 다음 noConflict 모드를 사용

jQuery(document).ready(function($) { 
    $.fn.snow(); 
}); 

내가 Snowfall version 1.4 테스트 그리고 이것은이다 작업 코드 (참고 jquerysnowfall에 대한 종속성으로 대기열에 포함됩니다. Plugin Demo Class 밖으로

add_action('plugins_loaded', 'wp_snowfall_plugins_loaded'); 

/* Initializes the plugin and it's features. */ 
function wp_snowfall_plugins_loaded() { 
    /* Set constant path to the members plugin directory. */ 
    define('WP_SNOWFALL_DIR', plugin_dir_path(__FILE__)); 

    /* Set constant path to the members plugin directory. */ 
    define('WP_SNOWFALL_URL', plugin_dir_url(__FILE__)); 

    /* Loads the snowfall. */ 
    add_action('wp_head', 'wp_snowfall_source'); 

    /* Startup the snowfall. */ 
    add_action('wp_footer', 'wp_snowfall_effect', 999); 
} 


function wp_snowfall_source() { 
    wp_enqueue_script('snowfall', WP_SNOWFALL_URL.'snowfall.min.jquery.js', array('jquery'));  
} 

function wp_snowfall_effect() { 
    ?> 
    <script type="text/javascript"> 
    jQuery(document).ready(function($) { 
     $(document).snowfall(); 
    }); 
    </script> 
    <?php 
} 

확인, 그것은 당신의 기본 플러그인을 업그레이드 할 수 있습니다. ... 상수를 좋은 연습이되지 않은 사용 또한

, 연구 워드 프레스 답변, 유용한 정보를 많이에서 plugin-development 태그)

관련 문제