mnsshsgfy

код слайдер стандартного

Jul 15th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. <?php
  2. /**
  3. * Modality functions and definitions
  4. *
  5. * @package Modality
  6. */
  7.  
  8. function modality_ideal_slider() {
  9. global $post;
  10. $modality_theme_options = modality_get_options( 'modality_theme_options' );
  11. $slider_cat = $modality_theme_options['image_slider_cat'];
  12. $num_of_slides = $modality_theme_options['slider_num'];
  13.  
  14. $modality_slider_query = new WP_Query(
  15. array(
  16. 'posts_per_page' => $num_of_slides,
  17. 'cat' => $slider_cat
  18. )
  19. );?>
  20. <div class="clear"></div>
  21. <div id="slider">
  22. <?php while ( $modality_slider_query->have_posts() ): $modality_slider_query->the_post(); ?>
  23. <?php if ($slider_cat !='') { ?>
  24. <?php if ( has_post_thumbnail() ) { ?>
  25. <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
  26. <img src="<?php echo esc_url($image[0]); ?>" title="<?php the_title_attribute(); ?>" alt="<?php esc_html(the_excerpt()); ?>" link="<?php esc_url(the_permalink()); ?>" />
  27. <?php } else { ?>
  28. <img class="attachment-full wp-post-image rs-slide-image" alt="slide" src="<?php echo esc_url(get_template_directory_uri().'/images/assets/slide.jpg');?>">
  29. <?php } ?>
  30. <?php } else { ?>
  31. <?php if ( has_post_thumbnail() ) { ?>
  32. <?php the_post_thumbnail('full'); ?>
  33. <?php } else { ?>
  34. <?php if ($slider_cat !='') { ?>
  35. <img class="attachment-full wp-post-image rs-slide-image" alt="slide" src="<?php echo esc_url(get_template_directory_uri().'/images/assets/slide.jpg');?>">
  36. <?php } else { ?>
  37. <img class="attachment-full wp-post-image rs-slide-image" alt="slide" src="<?php echo esc_url(get_template_directory_uri().'/images/assets/slide1.jpg');?>">
  38. <?php } ?>
  39. <?php } ?>
  40. <?php } ?>
  41. <?php endwhile; wp_reset_postdata(); ?>
  42. </div>
  43. <?php }
  44.  
  45. function modality_unslider_slider() {
  46. global $post;
  47. $modality_theme_options = modality_get_options( 'modality_theme_options' );
  48. $slider_cat = $modality_theme_options['image_slider_cat'];
  49. $num_of_slides = $modality_theme_options['slider_num'];
  50. $button_text = $modality_theme_options['caption_button_text'];
  51.  
  52. $modality_slider_query = new WP_Query(
  53. array(
  54. 'posts_per_page' => $num_of_slides,
  55. 'cat' => $slider_cat
  56. )
  57. );?>
  58. <div class="clear"></div>
  59. <div class="banner">
  60. <ul>
  61. <?php while ( $modality_slider_query->have_posts() ): $modality_slider_query->the_post(); ?>
  62. <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
  63. <li style="background: url(<?php echo esc_url($image[0]); ?>) 50% 0 no-repeat;">
  64. <?php if ($modality_theme_options['captions_on'] == '1') { ?>
  65. <div class="inner">
  66. <a class="post-title" href="<?php esc_url(the_permalink()); ?>"><h1><?php the_title(); ?></h1></a>
  67. <?php the_excerpt(); ?>
  68. </div>
  69. <?php if ($modality_theme_options['captions_button'] == '1') { ?>
  70. <a href="<?php esc_url(the_permalink()); ?>" class="btn"><?php echo $button_text ?></a>
  71. <?php }; ?>
  72. <?php }; ?>
  73. </li>
  74. <?php endwhile; wp_reset_postdata(); ?>
  75. </ul>
  76. </div>
  77. <div class="clear"></div>
  78.  
  79. <?php
  80. }
  81.  
  82. function modality_localize_scripts_ideal(){
  83. $modality_theme_options = modality_get_options( 'modality_theme_options' );
  84. $animation_speed = $modality_theme_options['animation_speed'];
  85. $slideshow_speed = $modality_theme_options['slideshow_speed'];
  86. $slider_height = $modality_theme_options['slider_height'];
  87. $slider_effect = $modality_theme_options['image_slider_effect'];
  88. $datatoBePassed = array(
  89. 'slideshowSpeed' => $slideshow_speed,
  90. 'animationSpeed' => $animation_speed,
  91. 'sliderHeight' => $slider_height,
  92. 'sliderEffect' => $slider_effect,
  93. );
  94. if ($modality_theme_options['captions_on'] == '1') {
  95. if (is_home() && ! is_paged()) {
  96. wp_enqueue_script( 'modality-slides-captions', get_template_directory_uri() .'/js/slides-captions.js' , array( 'jquery' ), '', true );
  97. wp_localize_script( 'modality-slides-captions', 'php_vars', $datatoBePassed );
  98. }
  99. }else{
  100. wp_enqueue_script( 'modality-ideal-slides', get_template_directory_uri() .'/js/ideal-slides.js' , array( 'jquery' ), '', true );
  101. wp_localize_script( 'modality-ideal-slides', 'php_vars', $datatoBePassed );
  102. }
  103.  
  104.  
  105. }
  106.  
  107. function modality_localize_scripts_unslider(){
  108. wp_enqueue_script( 'modality-slides', get_template_directory_uri() .'/js/slides.js' , array( 'jquery' ), '', true );
  109. $modality_theme_options = modality_get_options( 'modality_theme_options' );
  110. $animation_speed = $modality_theme_options['animation_speed'];
  111. $slideshow_speed = $modality_theme_options['slideshow_speed'];
  112. $datatoBePassed = array(
  113. 'slideshowSpeed' => $slideshow_speed,
  114. 'animationSpeed' => $animation_speed,
  115. );
  116. wp_localize_script( 'modality-slides', 'php_vars', $datatoBePassed );
  117. }
  118.  
  119. add_action( 'wp_enqueue_scripts', 'modality_localize_scripts_unslider' );
  120. add_action( 'wp_enqueue_scripts', 'modality_localize_scripts_ideal' );
Add Comment
Please, Sign In to add comment