wordpress插件的问题

时间:2012-08-23 07:29:10

标签: php 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');  

1 个答案:

答案 0 :(得分:0)

你应该在函数后面放add_action。 例如:

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

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