Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.94 KB | None | 0 0
  1. /**
  2.  * FUNCTIONS FOR GET URL IMAGES FROM CUSTOM FIELD ACF
  3.  */
  4. function get_url_post_custom_field_acf($post_id = null){
  5.     // GET CONTENT FROM ACF FIELD
  6.     $content = get_field('nome_campo_acf',$post_id);
  7.     // CREATE A EXPRESSION FOR GET URL IMG
  8.     $regex = '/src="([^"]*)"/';
  9.     // GET ALL MATCHES
  10.     preg_match_all( $regex, $content, $matches );
  11.     // REVERSING THE MATCHES ARRAY
  12.     $matches = array_reverse($matches);
  13.     // RETURN ARRAY URL IMAGES
  14.     return $matches[0];
  15. }
  16.  
  17. /**
  18.  * PUT JS INTO FOOTER SINGLE.PHP FOR SLIDE
  19.  */
  20. add_action('wp_footer','js_slider_field_acf', 20);
  21. function js_slider_field_acf(){
  22.     if(is_singular('post')){
  23.         ?>
  24.         <script type="text/javascript">
  25.         var slideIndex = 1;
  26.         showSlides(slideIndex);
  27.  
  28.         function plusSlides(n) {
  29.             showSlides(slideIndex += n);
  30.         }
  31.  
  32.         function currentSlide(n) {
  33.             showSlides(slideIndex = n);
  34.         }
  35.  
  36.         function showSlides(n) {
  37.             var i;
  38.             var slides = document.getElementsByClassName("mySlides");
  39.             if (n > slides.length) {slideIndex = 1}
  40.             if (n < 1) {slideIndex = slides.length}
  41.             for (i = 0; i < slides.length; i++) {
  42.                 slides[i].style.display = "none";
  43.             }
  44.  
  45.             slides[slideIndex-1].style.display = "block";
  46.             slides[slideIndex-1].className += " active";
  47.         }
  48.         </script>
  49.         <?php
  50.     }
  51. }
  52.  
  53. /**
  54.  * PUT CSS INTO FOOTER SINGLE.PHP FOR SLIDE
  55.  */
  56. add_action('wp_head','css_slider_field_acf', 20);
  57. function css_slider_field_acf($post_id){
  58.     if(is_singular('post')){
  59.         ?>
  60.         <style type="text/css">
  61.         /* Slideshow container */
  62.         .slideshow-container {
  63.           max-width: 1000px;
  64.           position: relative;
  65.           margin: auto;
  66.           clear: both;
  67.         }
  68.  
  69.         .slideshow-container img {vertical-align: middle;}
  70.         .slideshow-container .mySlides {display: none}
  71.  
  72.         /* Next & previous buttons */
  73.         .slideshow-container .prev, .slideshow-container .next {
  74.           cursor: pointer;
  75.           position: absolute;
  76.           top: 50%;
  77.           width: auto;
  78.           padding: 16px;
  79.           margin-top: -22px;
  80.           color: white;
  81.           font-weight: bold;
  82.           font-size: 18px;
  83.           transition: 0.6s ease;
  84.           border-radius: 0 3px 3px 0;
  85.         }
  86.  
  87.         /* Position the "next button" to the right */
  88.         .slideshow-container .next {
  89.           right: 0;
  90.           border-radius: 3px 0 0 3px;
  91.         }
  92.  
  93.         /* On hover, add a black background color with a little bit see-through */
  94.         .slideshow-container .prev:hover, .slideshow-container .next:hover {
  95.           background-color: rgba(0,0,0,0.8);
  96.         }
  97.  
  98.         /* Fading animation */
  99.         .slideshow-container .fade {
  100.           -webkit-animation-name: fade;
  101.           -webkit-animation-duration: 1.5s;
  102.           animation-name: fade;
  103.           animation-duration: 1.5s;
  104.         }
  105.  
  106.         @-webkit-keyframes fade {
  107.           from {opacity: .4}
  108.           to {opacity: 1}
  109.         }
  110.  
  111.         @keyframes fade {
  112.           from {opacity: .4}
  113.           to {opacity: 1}
  114.         }
  115.  
  116.         /* On smaller screens, decrease text size */
  117.         @media only screen and (max-width: 300px) {
  118.           .slideshow-container .prev, .slideshow-container .next, .slideshow-container .text {font-size: 11px}
  119.         }
  120.         </style>
  121.         <?php
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement