2012-12-10 237 views
0

內精選文章我也跟着下面的教程: - http://www.tutorialstag.com/wordpress-featured-posts-using-nivo-slider.html#codesyntax_1使用NIVO滑塊

使用精選文章功能的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'); 

?> 

誰能幫助?謝謝

+0

您是否查看過頁面的源代碼以查看圖片是否存在? – Anagio

+0

這是一個很好的問題...不。它不顯示我的圖像,雖然它在後... –

+0

所以短代碼功能工作? – Anagio

回答

0

插件的JavaScript可能與其他人發生衝突,因爲我面臨同樣的問題。你檢查了控制檯的JavaScript錯誤?

+0

請給你的答案npt的意見 –