0

我遵循了以下教程:- http://www.tutorialstag.com/wordpress-featured-posts-using-nivo-slider.html#codesyntax_1

使用特色帖子功能将 nivoslider 集成到我的主题中。然而,滑块似乎没有加载。JS 和 CSS 正在加载,但没有图像。

我已将帖子设置为特色图片,但再次没有运气。

请看下面我的函数文件:

<?php
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
wp_enqueue_script('jquery');

wp_register_script( 'jquery-ui', get_template_directory_uri().'/js/jquery-ui.min.js', array('jquery'), true );
wp_enqueue_script( 'jquery-ui' );

wp_register_script( 'custom', get_template_directory_uri().'/js/custom.js', array('jquery-ui'), true );
wp_enqueue_script( 'custom' );

wp_register_script( 'superfish', get_template_directory_uri().'/js/superfish.js', array('jquery'), true );
wp_enqueue_script( 'superfish' );
}
?>
<?php register_nav_menu('main', 'Main navigation menu'); ?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Footer',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<center><h2>',
'after_title' => '</h2></center>',
));
register_sidebar(array(
'name' => 'Footer Widget 1',
'id'        => 'footer-1',
'description' => 'First footer widget area',
'before_widget' => '<div id="footer-widget1">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Footer Widget 2',
'id'        => 'footer-2',
'description' => 'Second footer widget area',
'before_widget' => '<div id="footer-widget2">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Footer Widget 3',
'id'        => 'footer-3',
'description' => 'Third footer widget area',
'before_widget' => '<div id="footer-widget3">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
?>
<?php
/**
Wordpress Featured Posts with Nivo Slider
*
Author: Kannan C
url: http://www.tutorialstag.com/wordpress-featured-posts-using-nivo-slider.html
*/
//Paste the following code to your theme's functions.php file
//Don't forget to place the required Nivo slider files in to your theme's folder. Otherwise, the slider cannot work.
add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'sliding-images', 800, 400, true );
}   
//Featured posts using Nivo Slider
add_action("admin_init", "selection_meta_box");
function selection_meta_box(){
//add_meta_box("featured-post", "Set Featured", "featured_post", "post", "side", "low"); Uncomment this line and comment the below foreach loop if you want the Set Featured option only for posts
$post_types_array = get_post_types();
foreach ( $post_types_array as $post_type ) {
add_meta_box("featured-post", "Set Featured", "featured_post", $post-type, "side", "low");
}
}
function featured_post(){
global $post;
$meta_data = get_post_custom($post->ID);
$featured_post = $meta_data["_featured_post"][0];
$selected = ($meta_data["_featured_post"][0] == "yes") ? 'checked' : '';
echo "<p>";
echo "<input $selected type='checkbox' name='featured_post' value='yes' />";
echo "<label>Select this post as Featured.</label>";
echo "</p>";
}
add_action('save_post', 'save_post_details');
function save_post_details(){
global $post;
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
    return;
    $featured_post = trim($_POST["featured_post"]);
    update_post_meta($post->ID, "_featured_post", $featured_post);
}

function show_featured_posts($numbers) {
    global $post;
    //get $numbers of featured posts
    $featured_posts_array = get_posts( 'post_type=any&meta_key=_featured_post&meta_value=yes&numberposts='.$numbers.'&post_status=publish');
    $output .= '<div class="slider-wrapper theme-default">';
    $output .= '<div class="ribbon"></div>';
    $output .= '<div id="slider" class="nivoSlider">';
    foreach ($featured_posts_array as $post) :  setup_postdata($post); 
    $nivo_title = "#nivo".get_the_ID(); //assign the postID as title of the image
    if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { 
    $output .= get_the_post_thumbnail(get_the_ID(), array(800,400), array( "class" => "post_thumbnail", 'title' => $nivo_title )); }
    $caption .= "<div id='nivo".get_the_ID()."' class='nivo-html-caption'>
            <h2><a href='".get_permalink()."'>".get_the_title()."</a></h2>
            ".get_the_excerpt()."
        </div>";
    endforeach;
    $output .= '</div>';
    $output .= $caption;
    $output .= '</div>';
    return $output;
    //reset WP query
    wp_reset_query();
}

function include_nivo_scripts() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
    wp_register_script( 'nivopack', get_bloginfo('template_directory').'/js/jquery.nivo.slider.pack.js');
    wp_enqueue_script( 'jquery' );
    wp_enqueue_script( 'nivopack' );
}    
add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'sliding-images', 800, 400, true );
}
add_action('wp_enqueue_scripts', 'include_nivo_scripts');

add_action('wp_print_styles', 'add_nivo_stylesheets');
function add_nivo_stylesheets() {
     wp_register_style('nivo_theme_style', get_bloginfo('template_directory').'/js/default.css');
     wp_register_style('nivo_main_style', get_bloginfo('template_directory').'/js/nivo-slider.css');
     wp_enqueue_style( 'nivo_theme_style');
     wp_enqueue_style( 'nivo_main_style');
}

add_action('wp_footer', 'nivo_functioncall');
function nivo_functioncall() {
    echo '<script type="text/javascript">
    $(window).load(function() {
    $("#slider").nivoSlider();
    });
    </script>';
}

function tg_featured_posts($atts, $content = null) {
    extract(shortcode_atts(array(
        "numbers" => '5'
    ), $atts));
    echo show_featured_posts($numbers);
}
add_shortcode('featured', 'tg_featured_posts');

?>

任何人都可以帮忙吗?谢谢

4

1 回答 1

0

由于我遇到了同样的问题,插件的 javascript 可能与其他插件的 javascript 冲突。您是否检查过控制台的 javascript 错误?

于 2014-01-27T08:24:07.153 回答