Advertisement
firoze

Responsive slider In wordpress

Dec 24th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.90 KB | None | 0 0
  1. // Responsive slider In wordpress
  2.  
  3. <!------------------------------------------------------------------------------------------------------------------------------->
  4. <div class="fix slider_area">
  5. <div class="fix stracture slider">
  6. <!--------------Slideshow--------------->
  7.  
  8. <div class="rslides_container">
  9. <ul class="rslides" id="slider">
  10. <?php if(!is_paged()) { ?>
  11. <?php
  12. $args = array( 'post_type' => 'slider_polo', 'posts_per_page' => -1 ); // thiscome from custom-posts.php
  13. $loop = new WP_Query( $args );
  14. ?>
  15. <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
  16. <!---------------------------------------------------------->
  17. <li><?php the_post_thumbnail('slider_polo_size', array('class' => '')); ?></li> <!--here is our data--->
  18. <!----------------------------------------------------------->
  19. <?php endwhile; ?>
  20. <?php wp_reset_query(); ?>
  21. <?php } ?>
  22. </ul>
  23. </div>
  24.  
  25. </div>
  26. </div>
  27. <!-------------------------------------------------------------------------------------------------------------------------------->
  28. // functions.php
  29. add_theme_support( 'post-thumbnails', array( 'post','slider_polo' ) );
  30. add_image_size( 'slider_polo_size', 940, 222, true );
  31. <!-------------------------------------------------------------------------------------------------------------------------------->
  32. // custom-posts.php
  33. //register_post_type cannot exceed 20 characters in length
  34. register_post_type( 'slider_polo', //this post type name will go like (html page & example-functions.php =pages'=> array) where our post will display
  35. array(
  36. 'labels' => array(
  37. 'name' => __( 'Responsive Polo Slider' ),
  38. 'singular_name' => __( 'responsive polo slider' ),
  39. 'add_new'=>_('Add New responsive polo slider')
  40. ),
  41. 'public' => true,
  42. 'menu_icon'=> 'dashicons-format-gallery', /* For Dashicons Menu */
  43. 'has_archive' => true,
  44. 'rewrite'=> array( 'slug' => 'responsive polo slider' ),
  45. 'supports'=> array( 'title', 'thumbnail' )
  46. )
  47. );
  48. <!-------------------------------------------------------------------------------------------------------------------------------->
  49. // responsiveslides.js
  50.  
  51. /*! ResponsiveSlides.js v1.32
  52. * http://responsiveslides.com
  53. * http://viljamis.com
  54. *
  55. * Copyright (c) 2011-2012 @viljamis
  56. * Available under the MIT license
  57. */
  58.  
  59. /*jslint browser: true, sloppy: true, vars: true, plusplus: true, indent: 2 */
  60.  
  61. jQuery(function ($, window, i) {
  62. $.fn.responsiveSlides = function (options) {
  63.  
  64. // Default settings
  65. var settings = $.extend({
  66. "auto": true, // Boolean: Animate automatically, true or false
  67. "speed": 1000, // Integer: Speed of the transition, in milliseconds
  68. "timeout": 4000, // Integer: Time between slide transitions, in milliseconds
  69. "pager": false, // Boolean: Show pager, true or false
  70. "nav": false, // Boolean: Show navigation, true or false
  71. "random": false, // Boolean: Randomize the order of the slides, true or false
  72. "pause": false, // Boolean: Pause on hover, true or false
  73. "pauseControls": false, // Boolean: Pause when hovering controls, true or false
  74. "prevText": "Previous", // String: Text for the "previous" button
  75. "nextText": "Next", // String: Text for the "next" button
  76. "maxwidth": "", // Integer: Max-width of the slideshow, in pixels
  77. "controls": "", // Selector: Where controls should be appended to, default is after the <ul>
  78. "namespace": "rslides", // String: change the default namespace used
  79. before: function () {}, // Function: Before callback
  80. after: function () {} // Function: After callback
  81. }, options);
  82.  
  83. return this.each(function () {
  84.  
  85. // Index for namespacing
  86. i++;
  87.  
  88. var $this = $(this),
  89.  
  90. // Local variables
  91. selectTab,
  92. startCycle,
  93. restartCycle,
  94. rotate,
  95. $tabs,
  96.  
  97. // Helpers
  98. index = 0,
  99. $slide = $this.children(),
  100. length = $slide.size(),
  101. fadeTime = parseFloat(settings.speed),
  102. waitTime = parseFloat(settings.timeout),
  103. maxw = parseFloat(settings.maxwidth),
  104.  
  105. // Namespacing
  106. namespace = settings.namespace,
  107. namespaceIdx = namespace + i,
  108.  
  109. // Classes
  110. navClass = namespace + "_nav " + namespaceIdx + "_nav",
  111. activeClass = namespace + "_here",
  112. visibleClass = namespaceIdx + "_on",
  113. slideClassPrefix = namespaceIdx + "_s",
  114.  
  115. // Pager
  116. $pager = $("<ul class='" + namespace + "_tabs " + namespaceIdx + "_tabs' />"),
  117.  
  118. // Styles for visible and hidden slides
  119. visible = {"float": "left", "position": "relative"},
  120. hidden = {"float": "none", "position": "absolute"},
  121.  
  122. // Fading animation
  123. slideTo = function (idx) {
  124. settings.before();
  125. $slide
  126. .stop()
  127. .fadeOut(fadeTime, function () {
  128. $(this)
  129. .removeClass(visibleClass)
  130. .css(hidden);
  131. })
  132. .eq(idx)
  133. .fadeIn(fadeTime, function () {
  134. $(this)
  135. .addClass(visibleClass)
  136. .css(visible);
  137. settings.after();
  138. index = idx;
  139. });
  140. };
  141.  
  142. // Random order
  143. if (settings.random) {
  144. $slide.sort(function () {
  145. return (Math.round(Math.random()) - 0.5);
  146. });
  147. $this
  148. .empty()
  149. .append($slide);
  150. }
  151.  
  152. // Add ID's to each slide
  153. $slide.each(function (i) {
  154. this.id = slideClassPrefix + i;
  155. });
  156.  
  157. // Add max-width and classes
  158. $this.addClass(namespace + " " + namespaceIdx);
  159. if (options && options.maxwidth) {
  160. $this.css("max-width", maxw);
  161. }
  162.  
  163. // Hide all slides, then show first one
  164. $slide
  165. .hide()
  166. .eq(0)
  167. .addClass(visibleClass)
  168. .css(visible)
  169. .show();
  170.  
  171. // Only run if there's more than one slide
  172. if ($slide.size() > 1) {
  173.  
  174. // Make sure the timeout is at least 100ms longer than the fade
  175. if (waitTime < fadeTime + 100) {
  176. return;
  177. }
  178.  
  179. // Pager
  180. if (settings.pager) {
  181. var tabMarkup = [];
  182. $slide.each(function (i) {
  183. var n = i + 1;
  184. tabMarkup +=
  185. "<li>" +
  186. "<a href='#' class='" + slideClassPrefix + n + "'>" + n + "</a>" +
  187. "</li>";
  188. });
  189. $pager.append(tabMarkup);
  190.  
  191. $tabs = $pager.find("a");
  192.  
  193. // Inject pager
  194. if (options.controls) {
  195. $(settings.controls).append($pager);
  196. } else {
  197. $this.after($pager);
  198. }
  199.  
  200. // Select pager item
  201. selectTab = function (idx) {
  202. $tabs
  203. .closest("li")
  204. .removeClass(activeClass)
  205. .eq(idx)
  206. .addClass(activeClass);
  207. };
  208. }
  209.  
  210. // Auto cycle
  211. if (settings.auto) {
  212.  
  213. startCycle = function () {
  214. rotate = setInterval(function () {
  215.  
  216. // Clear the event queue
  217. $slide.stop(true, true);
  218.  
  219. var idx = index + 1 < length ? index + 1 : 0;
  220.  
  221. // Remove active state and set new if pager is set
  222. if (settings.pager) {
  223. selectTab(idx);
  224. }
  225.  
  226. slideTo(idx);
  227. }, waitTime);
  228. };
  229.  
  230. // Init cycle
  231. startCycle();
  232. }
  233.  
  234. // Restarting cycle
  235. restartCycle = function () {
  236. if (settings.auto) {
  237. // Stop
  238. clearInterval(rotate);
  239. // Restart
  240. startCycle();
  241. }
  242. };
  243.  
  244. // Pause on hover
  245. if (settings.pause) {
  246. $this.hover(function () {
  247. clearInterval(rotate);
  248. }, function () {
  249. restartCycle();
  250. });
  251. }
  252.  
  253. // Pager click event handler
  254. if (settings.pager) {
  255. $tabs.bind("click", function (e) {
  256. e.preventDefault();
  257.  
  258. if (!settings.pauseControls) {
  259. restartCycle();
  260. }
  261.  
  262. // Get index of clicked tab
  263. var idx = $tabs.index(this);
  264.  
  265. // Break if element is already active or currently animated
  266. if (index === idx || $("." + visibleClass + ":animated").length) {
  267. return;
  268. }
  269.  
  270. // Remove active state from old tab and set new one
  271. selectTab(idx);
  272.  
  273. // Do the animation
  274. slideTo(idx);
  275. })
  276. .eq(0)
  277. .closest("li")
  278. .addClass(activeClass);
  279.  
  280. // Pause when hovering pager
  281. if (settings.pauseControls) {
  282. $tabs.hover(function () {
  283. clearInterval(rotate);
  284. }, function () {
  285. restartCycle();
  286. });
  287. }
  288. }
  289.  
  290. // Navigation
  291. if (settings.nav) {
  292. var navMarkup =
  293. "<a href='#' class='" + navClass + " prev'>" + settings.prevText + "</a>" +
  294. "<a href='#' class='" + navClass + " next'>" + settings.nextText + "</a>";
  295.  
  296. // Inject navigation
  297. if (options.controls) {
  298. $(settings.controls).append(navMarkup);
  299. } else {
  300. $this.after(navMarkup);
  301. }
  302.  
  303. var $trigger = $("." + namespaceIdx + "_nav"),
  304. $prev = $("." + namespaceIdx + "_nav.prev");
  305.  
  306. // Click event handler
  307. $trigger.bind("click", function (e) {
  308. e.preventDefault();
  309.  
  310. // Prevent clicking if currently animated
  311. if ($("." + visibleClass + ":animated").length) {
  312. return;
  313. }
  314.  
  315. // Adds active class during slide animation
  316. // $(this)
  317. // .addClass(namespace + "_active")
  318. // .delay(fadeTime)
  319. // .queue(function (next) {
  320. // $(this).removeClass(namespace + "_active");
  321. // next();
  322. // });
  323.  
  324. // Determine where to slide
  325. var idx = $slide.index($("." + visibleClass)),
  326. prevIdx = idx - 1,
  327. nextIdx = idx + 1 < length ? index + 1 : 0;
  328.  
  329. // Go to slide
  330. slideTo($(this)[0] === $prev[0] ? prevIdx : nextIdx);
  331. if (settings.pager) {
  332. selectTab($(this)[0] === $prev[0] ? prevIdx : nextIdx);
  333. }
  334.  
  335. if (!settings.pauseControls) {
  336. restartCycle();
  337. }
  338. });
  339.  
  340. // Pause when hovering navigation
  341. if (settings.pauseControls) {
  342. $trigger.hover(function () {
  343. clearInterval(rotate);
  344. }, function () {
  345. restartCycle();
  346. });
  347. }
  348. }
  349.  
  350. }
  351.  
  352. // Max-width fallback
  353. if (typeof document.body.style.maxWidth === "undefined" && options.maxwidth) {
  354. var widthSupport = function () {
  355. $this.css("width", "100%");
  356. if ($this.width() > maxw) {
  357. $this.css("width", maxw);
  358. }
  359. };
  360.  
  361. // Init fallback
  362. widthSupport();
  363. $(window).bind("resize", function () {
  364. widthSupport();
  365. });
  366. }
  367.  
  368. });
  369.  
  370. };
  371. })(jQuery, this, 0);
  372.  
  373. <!--------------------------------------------------------------------------------------------------------------------------------->
  374. // responsiveslides.css
  375. /*! http://responsiveslides.com v1.32 by @viljamis */
  376.  
  377. .rslides {
  378. position: relative;
  379. list-style: none;
  380. overflow: hidden;
  381. width: 100%;
  382. padding: 0;
  383. margin: 0;
  384. }
  385.  
  386. .rslides li {
  387. position: absolute;
  388. display: none;
  389. width: 100%;
  390. left: 0;
  391. top: 0;
  392. }
  393.  
  394. .rslides li:first-child {
  395. position: relative;
  396. display: block;
  397. float: left;
  398. }
  399.  
  400. .rslides img {
  401. display: block;
  402. height:;
  403. float: left;
  404. width: 100%;
  405. border: 0;
  406. }
  407.  
  408. .rslides {
  409. margin: 0 auto;
  410. }
  411.  
  412. .rslides_container {
  413.  
  414. position: relative;
  415. }
  416.  
  417. .centered-btns_nav {
  418. position: absolute;
  419. -webkit-tap-highlight-color: rgba(0,0,0,0);
  420. top:50%;
  421. left: 0;
  422. opacity: 0.7;
  423. text-indent: -9999px;
  424. overflow: hidden;
  425. text-decoration: none;
  426. height: 61px;
  427. width: 38px;
  428. background: transparent url("../images/themes.gif") no-repeat left top;
  429. margin-top: -45px;
  430. }
  431.  
  432. .centered-btns_nav:active {
  433. opacity: 1.0;
  434. }
  435.  
  436. .centered-btns_nav.next {
  437. left: auto;
  438. background-position: right top;
  439. right: 0;
  440. }
  441.  
  442. .transparent-btns_nav {
  443. position: absolute;
  444. -webkit-tap-highlight-color: rgba(0,0,0,0);
  445. top: 0;
  446. left: 0;
  447. display: block;
  448. background: #fff; /* Fix for IE6-9 */
  449. opacity: 0;
  450. filter: alpha(opacity=1);
  451. width: 48%;
  452. text-indent: -9999px;
  453. overflow: hidden;
  454. height: 91%;
  455. }
  456.  
  457. .transparent-btns_nav.next {
  458. left: auto;
  459. right: 0;
  460. }
  461.  
  462. .large-btns_nav {
  463. position: absolute;
  464. -webkit-tap-highlight-color: rgba(0,0,0,0);
  465. opacity: 0.6;
  466. text-indent: -9999px;
  467. overflow: hidden;
  468. top: 0;
  469. bottom: 0;
  470. left: 0;
  471. background: #000 url("../images/themes.gif") no-repeat left 50%;
  472. width: 38px;
  473. }
  474.  
  475. .large-btns_nav:active {
  476. opacity: 1.0;
  477. }
  478.  
  479. .large-btns_nav.next {
  480. left: auto;
  481. background-position: right 50%;
  482. right: 0;
  483. }
  484.  
  485. .centered-btns_nav:focus,
  486. .transparent-btns_nav:focus,
  487. .large-btns_nav:focus {
  488. outline: none;
  489. }
  490.  
  491. .centered-btns_tabs,
  492. .transparent-btns_tabs,
  493. .large-btns_tabs {
  494. margin-top: 10px;
  495. text-align: center;
  496. }
  497.  
  498. .centered-btns_tabs li,
  499. .transparent-btns_tabs li,
  500. .large-btns_tabs li {
  501. display: inline;
  502. float: none;
  503. _float: left;
  504. *float: left;
  505. margin-right: 5px;
  506. }
  507.  
  508. .centered-btns_tabs a,
  509. .transparent-btns_tabs a,
  510. .large-btns_tabs a {
  511. text-indent: -9999px;
  512. overflow: hidden;
  513. -webkit-border-radius: 15px;
  514. -moz-border-radius: 15px;
  515. border-radius: 15px;
  516. background: #ccc;
  517. background: rgba(0,0,0, .2);
  518. display: inline-block;
  519. _display: block;
  520. *display: block;
  521. -webkit-box-shadow: inset 0 0 2px 0 rgba(0,0,0,.3);
  522. -moz-box-shadow: inset 0 0 2px 0 rgba(0,0,0,.3);
  523. box-shadow: inset 0 0 2px 0 rgba(0,0,0,.3);
  524. width: 9px;
  525. height: 9px;
  526. }
  527.  
  528. .centered-btns_here a,
  529. .transparent-btns_here a,
  530. .large-btns_here a {
  531. background: #222;
  532. background: rgba(0,0,0, .8);
  533. }
  534.  
  535. <!--------------------------------------------------------------------------------------------------------------------------------->
  536. // keep this image into your images file
  537.  
  538. http://s23.postimg.org/nhgym7ahz/themes.gif
  539. <!---------------------------------------------------------------------------------------------------------------------------------->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement