CSS without javascript is created by codeconvey.com which I migrated to the WordPress Plugin. This is a request from one of the my visitors who has difficulty displaying the CSS slider library into the WordPress CMS site. Follow the short tutorial below
Table of Contents
Creating CSS Sliders Without Javascript
This library is created using only CSS3 and HTML5. The advantage of using the slider plugin is lightweight and has a good animation display.
Here is a piece of the CSS slider code that I took from the official site codeconvey.com
There is 1 main CSS file that is used so that the slider can run normally, namely component.css
component.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | /* Author: Ashfaq Ahmed @ Codeconvey. Author URI: http://www.codeconvey.com/ */ .imgslidersgt{ max-height: 400px; width: 100%; } #cc-slider { text-align: center; margin: 0 auto; max-width: 850px; position:relative; margin-bottom: 20px; } #cc-slider input { display: none; } #cc-slider label, a { color: #ef023f; cursor: pointer; text-decoration: none; } #cc-slider label:hover { color: #ff0042 !important; } #slide1:checked ~ #cc-slides .inner { margin-left:0; } #slide2:checked ~ #cc-slides .inner { margin-left:-100%; } #slide3:checked ~ #cc-slides .inner { margin-left:-200%; } #slide4:checked ~ #cc-slides .inner { margin-left:-300%; } #slide5:checked ~ #cc-slides .inner { margin-left:-400%; } #overflow { width: 100%; overflow: hidden; } #cc-slides article img { width: 100%; } #cc-slides .inner { width: 500%; line-height: 0; } #cc-slides article { width: 20%; float: left; } #controls { margin: -8% 0 0 84%; width: 15%; height: 50px; } #controls label { display: none; width: 50px; height: 50px; } #active { margin: 23% 0 0; text-align: center; } #active label { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; display: inline-block; width: 10px; height: 10px; background: #f89e67; } #active label:hover { background: #ccc; border-color: #777 !important; } #controls label:hover { opacity: 0.8; } #slide1:checked ~ #controls label:nth-child(2), #slide2:checked ~ #controls label:nth-child(3), #slide3:checked ~ #controls label:nth-child(4), #slide4:checked ~ #controls label:nth-child(5), #slide5:checked ~ #controls label:nth-child(1) { background: url('images/next.png') no-repeat; float: right; margin: 0 10px 0 0; display: block; background-color:#ef023f; } #slide1:checked ~ #controls label:nth-child(5), #slide2:checked ~ #controls label:nth-child(1), #slide3:checked ~ #controls label:nth-child(2), #slide4:checked ~ #controls label:nth-child(3), #slide5:checked ~ #controls label:nth-child(4) { background: url('images/prev.png') no-repeat; float: left; margin: 0 0 0 17px; display: block; background-color:#ef023f; } /* cctooltip Box */ .cctooltip { color: #FFFFFF; font-style: italic; line-height: 20px; margin-top: 250px; opacity: 0; position: absolute; text-align: left; -webkit-transform: translateZ(0); -webkit-transition: all 0.3s ease-out; -moz-transition: all 0.3s ease-out; -o-transition: all 0.3s ease-out; transition: all 0.3s ease-out; } .cctooltip h3 { color: #FFFFFF; margin: 0 0 5px; font-weight: normal; font-size: 16px; font-style: normal; background: none repeat scroll 0 0 #222222; padding: 5px; } .cctooltip h4 { color: #FFFFFF; margin: 0 0 5px; font-weight: normal; font-size: 14px; font-style: normal; background: none repeat scroll 0 0 #222222; padding: 5px; text-align:right; width:106px; } /* cc-slider Styling */ #cc-slides { margin: 45px 0 0; padding: 1%; background: #fff; } /* Animation */ #cc-slides .inner { -webkit-transform: translateZ(0); -webkit-transition: all 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); -moz-transition: all 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); -ms-transition: all 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); -o-transition: all 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); transition: all 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); /* easeInOutQuart */ -webkit-transition-timing-function: cubic-bezier(0.770, 0.000, 0.175, 1.000); -moz-transition-timing-function: cubic-bezier(0.770, 0.000, 0.175, 1.000); -ms-transition-timing-function: cubic-bezier(0.770, 0.000, 0.175, 1.000); -o-transition-timing-function: cubic-bezier(0.770, 0.000, 0.175, 1.000); transition-timing-function: cubic-bezier(0.770, 0.000, 0.175, 1.000); /* easeInOutQuart */ } #cc-slider { -webkit-transform: translateZ(0); -webkit-transition: all 0.5s ease-out; -moz-transition: all 0.5s ease-out; -o-transition: all 0.5s ease-out; transition: all 0.5s ease-out; } #controls label{ -webkit-transform: translateZ(0); -webkit-transition: opacity 0.2s ease-out; -moz-transition: opacity 0.2s ease-out; -o-transition: opacity 0.2s ease-out; transition: opacity 0.2s ease-out; } #slide1:checked ~ #cc-slides article:nth-child(1) .cctooltip, #slide2:checked ~ #cc-slides article:nth-child(2) .cctooltip, #slide3:checked ~ #cc-slides article:nth-child(3) .cctooltip, #slide4:checked ~ #cc-slides article:nth-child(4) .cctooltip, #slide5:checked ~ #cc-slides article:nth-child(5) .cctooltip { opacity: 1; -webkit-transition: all 1s ease-out 0.6s; -moz-transition: all 1s ease-out 0.6s; -o-transition: all 1s ease-out 0.6s; transition: all 1s ease-out 0.6s; } |
To try the slider, please use the following HTML code snippet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <article id="cc-slider"> <input checked="checked" name="cc-slider" id="slide1" type="radio"> <input name="cc-slider" id="slide2" type="radio"> <input name="cc-slider" id="slide3" type="radio"> <input name="cc-slider" id="slide4" type="radio"> <input name="cc-slider" id="slide5" type="radio"> <div id="cc-slides"> <div id="overflow"> <div class="inner"> <article> <div class="cctooltip"> <h3>Amazing / Photoshop / Photography</h3> <h4>By <a href="#">codeconvey</a></h4> </div> <img src="images/slide-1.jpg"> </article> <article> <div class="cctooltip"> <h3>Abstract Retro Photography</h3> <h4>By <a href="#">codeconvey</a></h4> </div> <img src="images/slide-2.jpg"> </article> <article> <div class="cctooltip"> <h3>Street Photography</h3> <h4>By <a href="#">codeconvey</a></h4> </div> <img src="images/slide-3.jpg"> </article> <article> <div class="cctooltip"> <h3>Portrait / Woman / Photography</h3> <h4>By <a href="#">codeconvey</a></h4> </div> <img src="images/slide-4.jpg"> </article> <article> <div class="cctooltip"> <h3>Fashion / Sport / Photography</h3> <h4>By <a href="#">codeconvey</a></h4> </div> <img src="images/slide-5.jpg"> </article> </div> </div> </div> <div id="controls"> <label for="slide1"></label> <label for="slide2"></label> <label for="slide3"></label> <label for="slide4"></label> <label for="slide5"></label> </div> </article> |
If run on your browser, the CSS slider result like the following gif image below:
You can download the complete project on http://codeconvey.com/pure-css-image-slider
How? Cool and easy right? the question is, how can the script above run on the WordPress CMS? I will share the code to make the CSS slider plugin working normally on your WordPress.
Migrate the CSS Slider Library to the WordPress Plugin
- Download the css slider source code in http://codeconvey.com/pure-css-image-slider.
- Create a folder called css-slider.
- Create a file named css-slider.php in the css-slider folder.
- Copy and paste the component.css file into the css-slider folder.
- Copy the images folder on the original source into the css-slider folder.
- Change the bit of code in component.css so the next and prev navigation image can display properly like the following code snippet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #slide1:checked ~ #controls label:nth-child(2), #slide2:checked ~ #controls label:nth-child(3), #slide3:checked ~ #controls label:nth-child(4), #slide4:checked ~ #controls label:nth-child(5), #slide5:checked ~ #controls label:nth-child(1) { background: url('images/next.png') no-repeat; float: right; margin: 0 10px 0 0; display: block; background-color:#ef023f; } #slide1:checked ~ #controls label:nth-child(5), #slide2:checked ~ #controls label:nth-child(1), #slide3:checked ~ #controls label:nth-child(2), #slide4:checked ~ #controls label:nth-child(3), #slide5:checked ~ #controls label:nth-child(4) { background: url('images/prev.png') no-repeat; float: left; margin: 0 0 0 17px; display: block; background-color:#ef023f; } |
Copy the following code in the css-slider.php file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | <?php /* Plugin Name: CSS Slider Plugin URI: https://seegatesite.com Description: CSS Slider For Wordpress Without JS Version: 1.0 Author: Sigit prasetya nugroho Author URI: https://seegatesite.com/ Raw Source Url: http://codeconvey.com/pure-css-image-slider */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ function sgt_css_slider_show() { global $post; $obj_name = query_posts( array( 'posts_per_page' => 5, 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); if (have_posts()) : echo '<article id="cc-slider">'; $loop=1; $i=1; $nox = 1; while (have_posts()) : the_post(); if($nox == 1){ echo '<input checked="checked" name="cc-slider" id="slide'.$nox.'" type="radio">'; }else{ echo '<input name="cc-slider" id="slide'.$nox.'" type="radio">'; } $nox++; endwhile; echo '<div id="cc-slides"> <div id="overflow"> <div class="inner">'; while (have_posts()) : the_post(); $ximage = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo '<article>'; echo ' <div class="cctooltip"> <h3>'; echo the_title(); echo '</h3> <h4>'; echo the_category(); echo '</h4> </div>'; echo ' <img class="imgslidersgt" src="'.$ximage.'"> '; echo '</article>'; endwhile; echo ' </div> </div> </div>'; $nox=1; echo ' <div id="controls">'; while (have_posts()) : the_post(); echo '<label for="slide'.$nox.'"></label>'; $nox++; endwhile; echo '</div>'; echo '</article>'; endif; } function sgt_enqueue_custom_stylesheets() { if (!is_admin()) { wp_enqueue_style( 'sgt-plugin-custom-css-slider', plugin_dir_url( __FILE__ ).'component.css' ); } } add_action( 'wp_enqueue_scripts', 'sgt_enqueue_custom_stylesheets', 11 ); ?> |
How to use the css-slider plugin on WordPress
- compress the css-slider folder into zip format.
- Install on your WordPress site.
- Put the following code to display the slider on the WordPress page, usually placed these code in the index.php file under <body>.
1 | <?php if ( function_exists('sgt_css_slider_show') ) { sgt_css_slider_show(); } ?> |
The results are as follows
Noteworthy in the query_posts section, you can change it as needed.
1 | query_posts( array( 'posts_per_page' => 5, 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); |
Read another article : Create a Responsive Jquery Slideshow With Flexslider for WordPress
Download the full source code at the following link
[sociallocker id=58]
CSS slider WordPress Plugin without javascript download link
[/sociallocker]
That’s a short tutorial on how to make WordPress sliders without javascript.
Leave a Reply