Created
November 27, 2014 06:48
-
-
Save vishalbasnet23/6553869c10049cdee700 to your computer and use it in GitHub Desktop.
Simple Slider with bootstrap carousel for WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action('init','register_post_type_slider'); | |
| function register_post_type_slider() { | |
| $labels = array( | |
| 'name' => __('Slider','_cpm'), | |
| 'singular_name' => __('Slider','_cpm'), | |
| 'add_new' => __('Add New Slider Image','_cpm'), | |
| 'add_new_item' => __('Add New Slider Image','_cpm'), | |
| 'edit_item' => __('Edit Slider Image','_cpm'), | |
| 'new_item' => __('New Slider Image','_cpm'), | |
| 'all_items' => __('All Slider Images','_cpm'), | |
| 'view_item' => __('View Slider','_cpm'), | |
| 'search_items' => __('Search Slider Images','_cpm'), | |
| 'not_found' => __('No Slider Image found','_cpm'), | |
| 'not_found_in_trash' => __('No Slider Image found in Trash','_cpm'), | |
| 'parent_item_colon' => '', | |
| 'menu_name' => __('Slider','_cpm') | |
| ); | |
| $args = array( | |
| 'labels' => $labels, | |
| 'description' => __('Holds all the galley','_cpm'), | |
| 'public' => true, | |
| 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ), | |
| 'has_archive' => true, | |
| 'hierarchical' => true | |
| ); | |
| register_post_type( 'code_slider', $args ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="slider-wrapper"> | |
| <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> | |
| <?php | |
| $slider_args = array( | |
| 'post_type' => 'code_slider', | |
| 'posts_per_page'=> -1, | |
| 'post_status' => 'publish' | |
| ); | |
| $slider_query = new WP_Query( $slider_args ); | |
| $slider_count = 0; | |
| ?> | |
| <!-- Indicators --> | |
| <ol class="carousel-indicators"> | |
| <?php for( $indicator = 0; $indicator < $slider_query->post_count; $indicator++ ) { ?> | |
| <li data-target="#carousel-example-generic" data-slide-to="<?php echo $indicator;?>" <?php if( $indicator == 0 ) echo 'class="active"'; ?>></li> | |
| <?php } ?> | |
| </ol> | |
| <!-- Wrapper for slides --> | |
| <div class="carousel-inner" role="listbox"> | |
| <?php while ( $slider_query->have_posts() ) : $slider_query->the_post(); ?> | |
| <div <?php if( $slider_count == 0 ) echo 'class="item active"'; else echo 'class="item"';?>> | |
| <img src="<?php echo bloginfo('template_url');?>/images/banner2.jpg" alt="banner" class="img-responsive"> | |
| <div class="carousel-caption"> | |
| <h2><?php the_title(); ?></h2> | |
| <?php if( get_field('slider_place_button') == 1 ) :?> | |
| <p><?php echo code_content(20);?></p> | |
| <span class="custom-button"><a href="<?php the_field('slider_button_link');?>" class="custom-uniform-btn"><?php the_field('slider_button_text');?></a></span> | |
| <?php else : ?> | |
| <p><?php the_content();?></p> | |
| <?php endif; ?> | |
| </div> | |
| </div> | |
| <?php $slider_count++; endwhile; ?> | |
| </div> | |
| </div> | |
| <!--control is removed coz there isn't control arrow in design, in case if you want it then copy from bootstrap--> | |
| </div><!--slider wrapper ends--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment