24个滑块导航不起作用

时间:2014-03-21 作者:user41067

我想将导航添加到默认滑块。2014年的js。我尝试了很多方法,但我不知道我该怎么做。对此有什么建议吗?

指数php

<div class="slider">
<?php 
    query_posts(\'post_type=slider\');
    if (have_posts()) { 
        $slider_index=1;
        while(have_posts()): the_post(); $image=wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), \'home_slider\');?>

            <div rel="<?php echo $slider_index;?>" class="slide_element">
                <img src="<?php echo $image[0];?>" title="<?php the_title();?>" />
                <div class="center">
                    <h2><?php echo get_the_excerpt();?></h2>

                    <?php } ?>
                </div>
            </div>
        <?php $slider_index++; endwhile;?>     
滑块。js公司

    // Default settings.
$.featuredslider.defaults = {
    namespace: \'slider-\',     // String: prefix string attached to the class of every element generated by the plugin.
    selector: \'.slides > li\', // String: selector, must match a simple pattern.
    animationSpeed: 600,      // Integer: Set the speed of animations, in milliseconds.
    controlsContainer: \'\',    // jQuery Object/Selector: container navigation to append elements.

    // Text labels.
    directionNav: true, //Boolean: Create navigation for previous/next navigation? (true/false)
    prevText: featuredSliderDefaults.prevText, // String: Set the text for the "previous" directionNav item.
    nextText: featuredSliderDefaults.nextText  // String: Set the text for the "next" directionNav item.

};

1 个回复
SO网友:Pieter Goosen

你可以去看看this tutorial 作者:Josh Pollock。我已经摘录了该教程的部分内容。

添加这些选项将允许您在管理界面中设置移动版面和每个版面的帖子数量,如果您想更改设置,则无需更改代码。

    function awesome_2014_customize_register() {

global $wp_customize;

//add extended featured content section

//add controls
$wp_customize->add_setting( \'num_posts_grid\', array( \'default\' => \'6\' ) );
$wp_customize->add_setting( \'num_posts_slider\', array( \'default\' => \'6\' ) );
$wp_customize->add_setting( \'layout_mobile\', array( \'default\' => \'grid\' ) );

$wp_customize->add_control( \'num_posts_grid\', array(
\'label\' => __( \'Number of posts for grid\', \'text-domain\'),
\'section\' => \'featured_content\',
\'settings\' => \'num_posts_grid\',
) );

$wp_customize->add_control( \'num_posts_slider\', array(
\'label\' => __( \'Number of posts for slider\', \'text-domain\'),
\'section\' => \'featured_content\',
\'settings\' => \'num_posts_slider\',
) );

$wp_customize->add_control( \'layout_mobile\', array(
\'label\' => __( \'Layout for mobile devices\', \'text-domain\'),
\'section\' => \'featured_content\',
\'settings\' => \'layout_mobile\',
\'type\' => \'select\',
\'choices\' => array(
\'grid\' => \'Grid\',
\'slider\' => \'Slider\',
),
) );
}

add_action( \'customize_register\', \'awesome_2014_customize_register\' );
为移动设备指定不同的布局

 function awesome_2014_theme_mod( $value ) {

    if ( wp_is_mobile() ){
    return get_theme_mod( \'layout_mobile\', \'grid\' );
    } else {
    return $value;
    }
    }

    add_filter( \'theme_mod_featured_content_layout\', \'awesome_2014_theme_mod\' );

> Setting the Number of Posts For Each Layout

function awesome_2014_get_featured_posts( $posts ){

$fc_options = (array) get_option( \'featured-content\' );

if ( $fc_options ) {
$tag_name = $fc_options[\'tag-name\'];
} else {
$tag_name = \'featured\';
}

$layout = get_theme_mod( \'featured_content_layout\' );
$max_posts = get_theme_mod( \'num_posts_\' . $layout, 2 );

$args = array(
\'tag\' => $tag_name,
\'posts_per_page\' => $max_posts,
\'order_by\' => \'post_date\',
\'order\' => \'DESC\',
\'post_status\' => \'publish\',
);

$new_post_array = get_posts( $args );

if ( count($new_post_array) > 0 ) {
return $new_post_array;
} else {
return $posts;
}

}

add_filter( \'twentyfourteen_get_featured_posts\', \'awesome_2014_get_featured_posts\', 999, 1 );
使滑块自动滚动。现在,将此代码添加到函数中。php:

//dequeue/enqueue scripts
function awesome_2014_featured_content_scripts() {
wp_dequeue_script( \'twentyfourteen-script\' );
wp_dequeue_script( \'twentyfourteen-slider\' );

wp_enqueue_script( \'awesome_2014-script\', get_stylesheet_directory_uri() . \'/js/functions.js\', array( \'jquery\' ), \'\' , true );
if ( is_front_page() && \'slider\' == get_theme_mod( \'featured_content_layout\' ) ) {
wp_enqueue_script( \'awesome_2014-slider\', get_stylesheet_directory_uri() . \'/js/jquery.flexslider-min.js\', array( \'jquery\', \'awesome_2014-script\' ), \'\' , true );
wp_localize_script( \'awesome_2014-slider\', \'featuredSliderDefaults\', array(
\'prevText\' => __( \'Previous\', \'awesome_2014\' ),
\'nextText\' => __( \'Next\', \'awesome_2014\' )
) );
}
}
add_action( \'wp_enqueue_scripts\' , \'awesome_2014_featured_content_scripts\' , 999 );
这段代码还删除了父主题的两个函数。js文件。为了让滑块与Flexslider的完整版本无缝地工作,并确保应用现有的CSS,我们确实需要对主题的功能进行一些小的调整。js文件。将该文件复制到子主题的/js文件夹,打开它,并在底部用以下代码替换初始化特色内容滑块代码:

 // Initialize Featured Content slider.
_window.load( function() {
if ( body.is( \'.slider\' ) ) {
$( \'.featured-content\' ).flexslider( {
selector: \'.featured-content-inner > article\',
controlsContainer: \'.featured-content\',
slideshow: true,
slideshowSpeed: 4500,
namespace: \'slider-\',
} );
}
} );

结束

相关推荐

Sidebar slideshow widget

有人知道可以放在边栏上的高质量图像幻灯片小部件吗?

24个滑块导航不起作用 - 小码农CODE - 行之有效找到问题解决它

24个滑块导航不起作用

时间:2014-03-21 作者:user41067

我想将导航添加到默认滑块。2014年的js。我尝试了很多方法,但我不知道我该怎么做。对此有什么建议吗?

指数php

<div class="slider">
<?php 
    query_posts(\'post_type=slider\');
    if (have_posts()) { 
        $slider_index=1;
        while(have_posts()): the_post(); $image=wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), \'home_slider\');?>

            <div rel="<?php echo $slider_index;?>" class="slide_element">
                <img src="<?php echo $image[0];?>" title="<?php the_title();?>" />
                <div class="center">
                    <h2><?php echo get_the_excerpt();?></h2>

                    <?php } ?>
                </div>
            </div>
        <?php $slider_index++; endwhile;?>     
滑块。js公司

    // Default settings.
$.featuredslider.defaults = {
    namespace: \'slider-\',     // String: prefix string attached to the class of every element generated by the plugin.
    selector: \'.slides > li\', // String: selector, must match a simple pattern.
    animationSpeed: 600,      // Integer: Set the speed of animations, in milliseconds.
    controlsContainer: \'\',    // jQuery Object/Selector: container navigation to append elements.

    // Text labels.
    directionNav: true, //Boolean: Create navigation for previous/next navigation? (true/false)
    prevText: featuredSliderDefaults.prevText, // String: Set the text for the "previous" directionNav item.
    nextText: featuredSliderDefaults.nextText  // String: Set the text for the "next" directionNav item.

};

1 个回复
SO网友:Pieter Goosen

你可以去看看this tutorial 作者:Josh Pollock。我已经摘录了该教程的部分内容。

添加这些选项将允许您在管理界面中设置移动版面和每个版面的帖子数量,如果您想更改设置,则无需更改代码。

    function awesome_2014_customize_register() {

global $wp_customize;

//add extended featured content section

//add controls
$wp_customize->add_setting( \'num_posts_grid\', array( \'default\' => \'6\' ) );
$wp_customize->add_setting( \'num_posts_slider\', array( \'default\' => \'6\' ) );
$wp_customize->add_setting( \'layout_mobile\', array( \'default\' => \'grid\' ) );

$wp_customize->add_control( \'num_posts_grid\', array(
\'label\' => __( \'Number of posts for grid\', \'text-domain\'),
\'section\' => \'featured_content\',
\'settings\' => \'num_posts_grid\',
) );

$wp_customize->add_control( \'num_posts_slider\', array(
\'label\' => __( \'Number of posts for slider\', \'text-domain\'),
\'section\' => \'featured_content\',
\'settings\' => \'num_posts_slider\',
) );

$wp_customize->add_control( \'layout_mobile\', array(
\'label\' => __( \'Layout for mobile devices\', \'text-domain\'),
\'section\' => \'featured_content\',
\'settings\' => \'layout_mobile\',
\'type\' => \'select\',
\'choices\' => array(
\'grid\' => \'Grid\',
\'slider\' => \'Slider\',
),
) );
}

add_action( \'customize_register\', \'awesome_2014_customize_register\' );
为移动设备指定不同的布局

 function awesome_2014_theme_mod( $value ) {

    if ( wp_is_mobile() ){
    return get_theme_mod( \'layout_mobile\', \'grid\' );
    } else {
    return $value;
    }
    }

    add_filter( \'theme_mod_featured_content_layout\', \'awesome_2014_theme_mod\' );

> Setting the Number of Posts For Each Layout

function awesome_2014_get_featured_posts( $posts ){

$fc_options = (array) get_option( \'featured-content\' );

if ( $fc_options ) {
$tag_name = $fc_options[\'tag-name\'];
} else {
$tag_name = \'featured\';
}

$layout = get_theme_mod( \'featured_content_layout\' );
$max_posts = get_theme_mod( \'num_posts_\' . $layout, 2 );

$args = array(
\'tag\' => $tag_name,
\'posts_per_page\' => $max_posts,
\'order_by\' => \'post_date\',
\'order\' => \'DESC\',
\'post_status\' => \'publish\',
);

$new_post_array = get_posts( $args );

if ( count($new_post_array) > 0 ) {
return $new_post_array;
} else {
return $posts;
}

}

add_filter( \'twentyfourteen_get_featured_posts\', \'awesome_2014_get_featured_posts\', 999, 1 );
使滑块自动滚动。现在,将此代码添加到函数中。php:

//dequeue/enqueue scripts
function awesome_2014_featured_content_scripts() {
wp_dequeue_script( \'twentyfourteen-script\' );
wp_dequeue_script( \'twentyfourteen-slider\' );

wp_enqueue_script( \'awesome_2014-script\', get_stylesheet_directory_uri() . \'/js/functions.js\', array( \'jquery\' ), \'\' , true );
if ( is_front_page() && \'slider\' == get_theme_mod( \'featured_content_layout\' ) ) {
wp_enqueue_script( \'awesome_2014-slider\', get_stylesheet_directory_uri() . \'/js/jquery.flexslider-min.js\', array( \'jquery\', \'awesome_2014-script\' ), \'\' , true );
wp_localize_script( \'awesome_2014-slider\', \'featuredSliderDefaults\', array(
\'prevText\' => __( \'Previous\', \'awesome_2014\' ),
\'nextText\' => __( \'Next\', \'awesome_2014\' )
) );
}
}
add_action( \'wp_enqueue_scripts\' , \'awesome_2014_featured_content_scripts\' , 999 );
这段代码还删除了父主题的两个函数。js文件。为了让滑块与Flexslider的完整版本无缝地工作,并确保应用现有的CSS,我们确实需要对主题的功能进行一些小的调整。js文件。将该文件复制到子主题的/js文件夹,打开它,并在底部用以下代码替换初始化特色内容滑块代码:

 // Initialize Featured Content slider.
_window.load( function() {
if ( body.is( \'.slider\' ) ) {
$( \'.featured-content\' ).flexslider( {
selector: \'.featured-content-inner > article\',
controlsContainer: \'.featured-content\',
slideshow: true,
slideshowSpeed: 4500,
namespace: \'slider-\',
} );
}
} );

相关推荐

Sidebar slideshow widget

有人知道可以放在边栏上的高质量图像幻灯片小部件吗?