Created
March 15, 2018 23:37
-
-
Save CharlyJazz/a174f3fa418ee7396ba6b8bfff567daa to your computer and use it in GitHub Desktop.
Modal with you tube video
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 get_header(); | |
/* | |
Template Name: Testimonios | |
*/ | |
$args = [ | |
'post_type' => 'testimonials', | |
'order' => 'ASC', | |
'posts_per_page' => -1 | |
]; | |
$query = new WP_Query( $args ); | |
function getTemplatehtml($template){ | |
$class = ($template == 1) ? 'testimonies-col__article --with-border' : 'testimonies-col__article'; | |
$template = '<article class="'.$class.'"> | |
<div> | |
<div class="testimonies-video__div" data-youtube-id="%s"><img src="//img.youtube.com/vi/%s/0.jpg" alt=""></div> | |
<div class="testimonies-body"> | |
<p>%s</p> | |
<p><strong>%s (%s)</strong></p> | |
</div> | |
</div> | |
</article>'; | |
return $template; | |
} | |
function printTestimonies($query) | |
{ | |
$init = $count = 0; | |
$html_testimonie = getTemplatehtml(1); | |
$html_testimonie_3 = getTemplatehtml(2); | |
$data = []; | |
foreach ($query->posts as $testimonie) : setup_postdata($testimonie); | |
$count++; | |
$data_t = [ | |
'name' => get_post_meta($testimonie->ID, '_testimonials_name', true), | |
'des' => get_post_meta($testimonie->ID, '_testimonials_des', true), | |
'video' => get_post_meta($testimonie->ID, '_testimonials_video', true), | |
'content' => $testimonie->post_content | |
]; | |
array_push($data,$data_t); | |
if($count %3 == 0 && $init == 0){ | |
$count = 0; | |
$init = 1; | |
echo '<div class="testimonies-row__div">'; | |
foreach ($data as $key => $testimonie) { | |
if($key != 2){ | |
echo sprintf($html_testimonie,$testimonie['video'],$testimonie['video'],$testimonie['content'],$testimonie['des'],$testimonie['name']); | |
}else{ | |
echo sprintf($html_testimonie_3,$testimonie['video'],$testimonie['video'],$testimonie['content'],$testimonie['des'],$testimonie['name']); | |
} | |
} | |
echo '</div>'; | |
$data = []; | |
}elseif ($count %3 ==0 && $init == 1) { | |
$count = 0; | |
echo '<div class="testimonies-row__div --with-margin-top --with-border-top">'; | |
foreach ($data as $key => $testimonie) { | |
if($key != 2){ | |
echo sprintf($html_testimonie,$testimonie['video'],$testimonie['video'],$testimonie['content'],$testimonie['des'],$testimonie['name']); | |
}else{ | |
echo sprintf($html_testimonie_3,$testimonie['video'],$testimonie['video'],$testimonie['content'],$testimonie['des'],$testimonie['name']); | |
} | |
} | |
echo '</div>'; | |
$data = []; | |
} | |
endforeach; | |
wp_reset_postdata(); | |
} | |
?> | |
<div id="line-page-body"> | |
<section class="testimonies-wrapper-title__section"> | |
<h1>testimonios</h1> | |
</section> | |
<section class="testimonies-container__section"> | |
<?php printTestimonies($query); ?> | |
<!-- <div class="testimonies-row__div"> | |
<article class="testimonies-col__article --with-border"> | |
<div> | |
<div class="testimonies-video__div" data-youtube-id="1sIWez9HAbA"><img src="//img.youtube.com/vi/1sIWez9HAbA/0.jpg" alt=""></div> | |
<div class="testimonies-body"> | |
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Fugiat minus ullam numquam itaque doloribus dignissimos?</p> | |
<p><strong>Lorem, ipsum - Lorem ipsum dolor sit amet (Lorem, ipsum)</strong></p> | |
</div> | |
</div> | |
</article> | |
<article class="testimonies-col__article --with-border"> | |
<div> | |
<div class="testimonies-video__div" data-youtube-id="1sIWez9HAbA"><img src="//img.youtube.com/vi/1sIWez9HAbA/0.jpg" alt=""></div> | |
<div class="testimonies-body"> | |
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Fugiat minus ullam numquam itaque doloribus dignissimos?</p> | |
<p><strong>Lorem, ipsum - Lorem ipsum dolor sit amet (Lorem, ipsum)</strong></p> | |
</div> | |
</div> | |
</article> | |
<article class="testimonies-col__article"> | |
<div> | |
<div class="testimonies-video__div" data-youtube-id="1sIWez9HAbA"><img src="//img.youtube.com/vi/1sIWez9HAbA/0.jpg" alt=""></div> | |
<div class="testimonies-body"> | |
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Fugiat minus ullam numquam itaque doloribus dignissimos?</p> | |
<p><strong>Lorem, ipsum - Lorem ipsum dolor sit amet (Lorem, ipsum)</strong></p> | |
</div> | |
</div> | |
</article> | |
</div> | |
<div class="testimonies-row__div --with-margin-top --with-border-top"> | |
<article class="testimonies-col__article --with-border"> | |
<div> | |
<div class="testimonies-video__div" data-youtube-id="1sIWez9HAbA"><img src="//img.youtube.com/vi/1sIWez9HAbA/0.jpg" alt=""></div> | |
<div class="testimonies-body"> | |
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Fugiat minus ullam numquam itaque doloribus dignissimos?</p> | |
<p><strong>Lorem, ipsum - Lorem ipsum dolor sit amet (Lorem, ipsum)</strong></p> | |
</div> | |
</div> | |
</article> | |
<article class="testimonies-col__article --with-border"> | |
<div> | |
<div class="testimonies-video__div" data-youtube-id="1sIWez9HAbA"><img src="//img.youtube.com/vi/1sIWez9HAbA/0.jpg" alt=""></div> | |
<div class="testimonies-body"> | |
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Fugiat minus ullam numquam itaque doloribus dignissimos?</p> | |
<p><strong>Lorem, ipsum - Lorem ipsum dolor sit amet (Lorem, ipsum)</strong></p> | |
</div> | |
</div> | |
</article> | |
<article class="testimonies-col__article"> | |
<div> | |
<div class="testimonies-video__div" data-youtube-id="1sIWez9HAbA"><img src="//img.youtube.com/vi/1sIWez9HAbA/0.jpg" alt=""></div> | |
<div class="testimonies-body"> | |
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Fugiat minus ullam numquam itaque doloribus dignissimos?</p> | |
<p><strong>Lorem, ipsum - Lorem ipsum dolor sit amet (Lorem, ipsum)</strong></p> | |
</div> | |
</div> | |
</article> | |
</div> --> | |
</section> | |
<div class="line-container line-wrap"> | |
<div class="line-page-content"> | |
<!-- HTML --> | |
</div> | |
</div> | |
</div> | |
<script> | |
jQuery( document ).ready(function() { | |
jQuery('.testimonies-video__div').click(function() { | |
var width, height; | |
if (jQuery(window).width() < 600) { | |
width = Math.floor((jQuery(window).width() / 100) * 75); | |
height = width / 100 * 80; | |
} else if (jQuery(window).width() < 1100) { | |
width = 600; | |
height = width / 100 * 80; | |
} else { | |
width = 950; | |
height = 500 - 20; | |
} | |
jQuery('body').append('<div class="backdrop-wrapper__div"></div>') | |
jQuery('body').append( | |
'<div class="modal-wrapper__div"> \ | |
<div> \ | |
<iframe width="' + width + '" height="' + height +'" src="https://www.youtube.com/embed/' + jQuery(this).data()['youtubeId'] + '" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> \ | |
</div> \ | |
</div>' | |
) | |
jQuery('.backdrop-wrapper__div').click(function() { | |
jQuery('.modal-wrapper__div').addClass('--closing') | |
setTimeout(function() { | |
jQuery('.backdrop-wrapper__div').remove() | |
jQuery('.modal-wrapper__div').remove() | |
}, 1000) | |
}) | |
}) | |
}); | |
</script> | |
<!-- end content --> | |
<?php get_footer(); ?> |
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
/******************** Testimonies Page *******************/ | |
.testimonies-wrapper-title__section { | |
padding-top: 55px; | |
text-align: center; | |
margin-top: 6%; | |
border-bottom: 1px solid black | |
} | |
.testimonies-wrapper-title__section h1 { | |
font-size: 32px | |
} | |
.testimonies-container__section { | |
width: 100%; | |
} | |
.testimonies-row__div { | |
display: flex; | |
} | |
.testimonies-row__div.--with-border-top { | |
border-top: 1px solid black; | |
} | |
.testimonies-video__div { | |
height: 230px; | |
cursor: pointer; | |
overflow: hidden | |
} | |
.testimonies-video__div img { | |
max-width: 100%; | |
width: 100%; | |
height: auto; | |
} | |
.testimonies-row__div.--with-margin-top { | |
margin-top: 5px; | |
} | |
.testimonies-col__article { | |
width: 33.3333%; | |
padding: 20px; | |
position: relative; | |
} | |
.testimonies-col__article.--with-border:after { | |
content: ''; | |
width: 1px; | |
height: 280px; | |
background-color: black; | |
position: absolute; | |
top: 0; | |
right: -1px; | |
} | |
.testimonies-body { | |
min-height: 80px; | |
margin-top: 10px; | |
} | |
@media (max-width: 1080px) { | |
.testimonies-col__article.--with-border:after { | |
content: unset; | |
width: unset; | |
height: unset; | |
background-color: unset; | |
position: unset; | |
top: unset; | |
right: unset; | |
} | |
.testimonies-row__div.--with-border-top { | |
border-top: unset | |
} | |
} | |
@media (max-width: 1080px) { | |
.testimonies-row__div { | |
flex-direction: column; | |
} | |
.testimonies-col__article { | |
width: 100%; | |
} | |
.testimonies-col__article:not(.--without-pading-tablet) { | |
padding: 3% 20%; | |
} | |
.testimonies-body > p { | |
font-size: 1.2rem; | |
} | |
.testimonies-video__div { | |
height: 300px | |
} | |
} | |
@media (max-width: 768px) { | |
.testimonies-col__article { | |
padding: 3% 10%; | |
width: 100%; | |
} | |
.testimonies-body > p { | |
font-size: 1.25rem; | |
} | |
} | |
@media (max-width: 480px) { | |
.testimonies-col__article { | |
padding: 3% 5%; | |
width: 100%; | |
} | |
} | |
.backdrop-wrapper__div { | |
width: 100%; | |
height: 100%; | |
position: fixed; | |
z-index: 100; | |
left: 0; | |
top: 0; | |
background-color: rgba(0,0,0,0.85) | |
} | |
.modal-wrapper__div { | |
position: fixed; | |
z-index: 500; | |
background-color: #fff; | |
width: 90%; | |
border: 1px solid #ccc; | |
-webkit-box-shadow: 1px 1px 1px #000; | |
box-shadow: 1px 1px 1px #000; | |
padding: 16px; | |
left: 5%; | |
top: 10%; | |
-webkit-box-sizing: border-box; | |
box-sizing: border-box; | |
-webkit-transition: all .3s ease-out; | |
-o-transition: all .3s ease-out; | |
transition: all .3s ease-out; | |
animation: openModal 0.4s ease-out forwards; | |
} | |
.modal-wrapper__div > div { | |
text-align: center; | |
} | |
.modal-wrapper__div.--closing { | |
animation: closeModal 1s ease-out forwards; | |
} | |
@media (max-width: 600px) { | |
.modal-wrapper__div { | |
width: 95%; | |
top: 5%; | |
left: 2.5%; | |
} | |
} | |
@keyframes openModal { | |
0% { | |
opacity: 0; | |
transform: translateY(-100%); | |
} | |
50% { | |
opacity: 1; | |
transform: translateY(90%); | |
} | |
100% { | |
opacity: 1; | |
transform: translateY(0); | |
} | |
} | |
@keyframes closeModal { | |
0% { | |
opacity: 1; | |
transform: translateY(0); | |
} | |
50% { | |
opacity: 0.8; | |
transform: translateY(60%); | |
} | |
100% { | |
opacity: 0; | |
transform: translateY(-100%); | |
} | |
} | |
.block__information__wrapper { | |
text-align: center | |
} | |
.block__information__wrapper > img { | |
margin-top: 20px; | |
} | |
.block__information__wrapper.--with-margin-top { | |
margin-top: 80px | |
} | |
.block__information__wrapper:not(.--with-margin-top) { | |
margin-top: 60px; | |
} | |
.information-testimonies__div { | |
display: flex; | |
flex-direction: column; | |
} | |
@media (min-width: 980px) { | |
.information-testimonies__div { | |
flex-direction: row; | |
} | |
} | |
@media (min-width: 600px) { | |
.information-testimonies__div { | |
padding: 0 10% | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment