2012-08-23 33 views
0

插件的問題是該插件的代碼:在WordPress的

<?php 

     function np_init() { 
      $args = array( 
       'public' => true, 
       'label' => 'Nivo Images', 
       'supports' => array( 
        'title', 
        'thumbnail' 
       ) 
      ); 
      register_post_type('np_images', $args); 
     } 
     add_action('init', 'np_init'); 
      function np_widget{ 
       add_image_size('np_widget', 180, 100, true); 
     } 
     function np_function { 
     add_image_size('np_function', 600, 280, true); 
     } 
      ?> 
    <?php 
    /* 
     Plugin Name: Nivo Plugin 
     Description: Simple implementation of a nivo slideshow into wordpress 
     Author: Ciprian Turcu 
     Version: 1.0 
    */ 
    ?> 
     <?php function np_register_scripts() { 
      if (!is_admin()) { 
       // register 
       wp_register_script('np_nivo-script', plugins_url('nivo-slider/jquery.nivo.slider.js', __FILE__), array('jquery')); 
       wp_register_script('np_script', plugins_url('script.js', __FILE__)); 

       // enqueue 
       wp_enqueue_script('np_nivo-script'); 
       wp_enqueue_script('np_script'); 
      } 
     } 

     function np_register_styles() { 
      // register 
      wp_register_style('np_styles', plugins_url('nivo-slider/nivo-slider.css', __FILE__)); 
      wp_register_style('np_styles_theme', plugins_url('nivo-slider/themes/default/default.css', __FILE__)); 

      // enqueue 
      wp_enqueue_style('np_styles'); 
      wp_enqueue_style('np_styles_theme'); 
     } ?> 

我不知道在哪裏放置的代碼下面幾行:

add_action('wp_print_scripts', 'np_register_scripts'); 
add_action('wp_print_styles', 'np_register_styles'); 

回答

0

你應該把函數後右邊的add_action。 例如:

function np_script() 
{ 
..... 
..... 
} 
add_action('wp_print_scripts' , 'np_script'); 

function np_style() 
{ 
..... 
..... 
} 
add_action('wp_print_styles' , 'np_style'); 
+0

這是對的,但它是關於「邏輯流」。 首先你寫一個函數,然後告訴WP何時調用它。 –