Can somebody pls help me?
I'm currently working on a dynamic website. I have 2 navigations points and I have a video window on the right side. By clicking on one navigation point the respective video should appear in the video window. The problem is: my navigation list will be created dynamically and the video appearance as well (in this case the urls videos will be embedded from Youtube). Here is my PHP code where the list of navigation points will be created dynamically:
function reborn_videos($attribute){
ob_start();
$urls = $attribute['filme'];
$urls = explode(',', $urls);
?>
<div id="mobil_content">
<?php for($i=1; $i<= count($urls); $i++) {
$movie_title = $attribute['title'.$i];
?>
<div class="box">
<div class="box_title_video"><a class="expand"><?php echo $movie_title; ?> </a></div>
<?php foreach ($urls as $url) { ?>
<div class="box_body_iframe">
<iframe width="100%" height="315" src="https://www.youtube.com/embed/<?php echo trim($url); ?>" frameborder="0" allowfullscreen></iframe>
</div>
<?php } ?>
</div>
<?php } ?>
here is what i changed and looks right now:
function reborn_videos($attribute){
ob_start();
$urls = $attribute['filme'];
$urls = explode(',', $urls);
?>
<div id="mobil_content">
<?php for($i=1; $i<= count($urls); $i++) {
$movie_title = $attribute['title'.$i];
?>
<div class="box">
<div class="box_title_video"><a class="expand"><?php echo $movie_title; ?></a></div>
<div class="box_body_iframe">
<iframe width="100%" height="315" src="https://www.youtube.com/embed/<?php echo trim($urls[$i]); ?>" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<?php } ?>
and here the JQuery that I want to use to show and hide my videos:
var $alleVideos = $(".box_body_iframe");
function showVideos() {
$alleVideos.each(function(){
if ( $(this).hasClass('active') ) {
$(this).show();
} else{
$(this).hide();
}
});
}
$alleVideos.hide();
$(".box_title_video").click(function(){
$alleVideos.removeClass('active');
$(this).next().addClass('active');
showVideos();
});
in JQuery code i have no changes
this is how the Browser output the html code:
<div id="mobil_content">
<div class="box">
<div class="box_title_video">
<a class="expand">reborn</a>
</div>
<div class="box_body_iframe" style="display: none;">
<iframe height="315" frameborder="0" width="100%" allowfullscreen="" src="https://www.youtube.com/embed/7PnRkyu0HTs">
</div>
</div>
<div class="box">
<div class="box_title_video">
<a class="expand">trailer</a>
</div>
<div class="box_body_iframe active" style="display: block;">
<iframe height="315" frameborder="0" width="100%" allowfullscreen="" src="https://www.youtube.com/embed/">
</div>
</div>
</div>
The problem is: the JQuery animation just shows one and always the same video in the video window. :-(
The problem seems to be that you have a loop in your loop and both loops loop over all your urls:
for($i=1; $i<= count($urls); $i++)
...
foreach ($urls as $url)
So in every entry in the outer loop, you generate a list will all your videos. And you activate the first one of that list every time with $(this).next().addClass('active'); so you will always show the same, first, video.
You can probably solve your problem by replacing the inner loop with just the current item: $urls[$i]:
<div class="box_title_video"><a class="expand"><?php echo $movie_title; ?> </a></div>
<div class="box_body_iframe">
<iframe width="100%" height="315"
src="https://www.youtube.com/embed/<?php echo trim($urls[$i]); ?>"
frameborder="0" allowfullscreen></iframe>
</div>
</div>
Edit: I just noticed that your loop runs form 1 and arrays are zero-indexed, so you would need:
... src="https://www.youtube.com/embed/<?php echo trim($urls[$i - 1]); ?>" ...
^^^^^^^ here
Now you correctly show two blocks but as you can see in the second video, there is no url.
Related
Youtube video in a popup keeps playing after the popup is closed. There are multiple videos in popups on the page. The page is a wordpress loop.
I have my code working well just up to this point where I need to stop the video playing.
I am pretty sure that the solution is probably very simple. I have tried various things over the past 2 days and I still just can't get the videos to stop playing when I close the popup box. I have only managed so far to get the first video to stop playing with the commented piece inside my pasted code.
<div class="project-box">
<div id="close<?php the_permalink() ?>"></div>
<div class="project-box-image">
<div class="project-box-overlay">
<div class="project-overlay-links">
<a id="video-button" href="#<?php the_title(); ?>" class="button-link">Play video</a>
<a class="button-link" href="<?php the_permalink() ?>">View Project</a>
</div><!---project-overlay-links-->
</div><!---project-box-overlay-->
<div id="<?php the_title(); ?>" class="popup-overlay">
<div id="popup" class="popup">
<a class="close" href="#close<?php the_permalink() ?>">×</a>
<div class="content">
<?php if( get_field('pop_up_video') ): ?>
<div class="video-embed" >
<div id="youtube">
<iframe width="800" height="400" src="<?php the_field('pop_up_video'); ?>?autoplay=0&rel=0&enable_js=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div><!---youtube-->
</div><!---video-embed-->
<?php endif; ?>
<script>
$('.close').click(function(e) {
e.preventDefault();
//$('iframe').attr('src', '');
$('.popup-overlay').addClass('display-none');
/*$('.youtube').each(function(index) {
$(this).attr('src', $(this).attr('src'));
return false;
});
});*/
$('a#video-button').click(function(){
$('.popup-overlay').removeClass('display-none');
});
</script>
</div><!---content-->
</div><!---popup-->
</div><!---overlay-->
<?php the_post_thumbnail('service-box-image'); ?>
</div><!---project-box-image-->
<a href="<?php the_permalink() ?>">
<h5><?php the_title(); ?></h5>
</a>
<div class="post-tags">
<?php the_tags('', ', '); ?>
</div><!---post-tags-->
<p><?php the_excerpt(); ?></p>
</div><!---project-box-->
If I understand correctly, you have multiple popups? If so, the code to change the src will affect all dialogs.
I'm assuing you're changing the SRC to stop the video. Also, assuming that the .close_me element is within the .hide_overlay element, you can do this:
jQuery('.close_me').click(function (e) {
var $videoEl = jQuery(this).closest('.hide_overlay').find('iframe');
$videoEl.attr('src', $videoEl.attr('src'));
});
This works because jQuery(this) will target the specific close button related to that one popup, and not target all popups.
Technically, a nicer way to stop or pause a video is to use the Youtube Javascript API as you can do something like:
player.stopVideo();
I understand foreach but this is new for me because within the foreach in PHP I have some script for each item that shows up and wondering why it only works for the item in the first item
In the code, I am getting an image from an MYSQL database. instead of using onclick in js I am learning more into jquery and only when I click the first image it will generate the
$("#main").load("includes/product.php");
path and change I want to change but in the product name and the cart button do not change the visuals.
<section id="new-products" class="clearfix">
<div class="title-block">
<h4>New Products</h4>
</div>
<?PHP
foreach ($item as $items){
?>
<div class="left-col-block">
<article class="product-box clearfix">
<a href="#store/category/<?PHP echo $items['category'];?>/<?PHP echo $items['brand'];?>/<?PHP echo $items['name'];?>" id="product-link">
<img src="<?PHP echo $items['image']; ?>" alt="Card Games" title="Card Games" height="80" width="80">
</a>
<?PHP echo $items['name']; ?><br>
<span class="price">$<?php echo $items['price'];?></span>
</article>
`<script>
$( "#product-link" ).click(function() {
$("#main").load("includes/product.php");
});
</script>
</div>
<div class="left-col-block">
</div>
<?PHP
}
?>
</section>
Expected:
I am wanting each link with the id of product-link to give the event trigger with jquery on each product and each id
Actual Results:
$("#main").load("includes/product.php");
only works on the first id that is equal to product-link
because of you have 3 like for each item and you want to set on click for every 3 link, you must use class attribute and set it unique for each item.
I changed your code to this:
<section id="new-products" class="clearfix">
<div class="title-block">
<h4>New Products</h4>
</div>
<?PHP
foreach ($item as $key=>$items){
?>
<div class="left-col-block">
<article class="product-box clearfix">
<a href="#store/category/<?PHP echo $items['category'];?>/<?PHP echo $items['brand'];?>/<?PHP echo $items['name'];?>" class="product-link-<?=$key?>">
<img src="<?PHP echo $items['image']; ?>" alt="Card Games" title="Card Games" height="80" width="80">
</a>
<?PHP echo $items['name']; ?><br>
<span class="price">$<?php echo $items['price'];?></span>
</article>
`<script>
$( ".product-link-<?=$key?>" ).click(function() {
$("#main").load("includes/product.php");
});
</script>
</div>
<div class="left-col-block">
</div>
<?PHP
}
?>
</section>
Found the answer was
<script>$( ".product-box a" ).click(function() {
$("#main").load("includes/product.php");
});</script>
since product-bot was a class and I didn't realize the # makes it check for id and the. makes it search for a class and class is able to be called multiple times whereas an id has to be unique
<h5>
<a href="<?php echo base_url(); ?>/vendor/home/projects" >Back to Projects</a>
<h5>
<div>
<div class="container">
<div class="row">
<?php
foreach ($projects as $value) {
?>
<?php
$project_images = json_decode($value['project_gallery'],true);
$i=0;
foreach ($project_images as $project_image_value) {
$i++;
?>
<div class="col-md-2">
<img src="<?= base_url() ?>assets/uploads/projects/<?=$project_image_value['fname']?>" onclick="openModal(<?= $i?>)" class="img-thumbnail img-responsive " />
<div><?=$project_image_value['title']?></div>
</div> <?php
}
?>
<?php
}
?>
</div>
</div>
this is my codeigniter view to display images. How can i Apply light box so that when you click image, only that image should be zoomed
There are so many easy to use JQuery plugins available for image zoom kind of functionality. Use any of the following:
There use is as simple as:
$(document).ready(function(){
$('a.photo').zoom({url: 'photo-big.jpg'});
});
Reference
Some more reference:
https://i-like-robots.github.io/EasyZoom/
http://www.jqueryscript.net/tags.php?/image%20zoom/
http://www.jqueryscript.net/demo/Simple-jQuery-Magnifying-Glass-Image-Zoom-Plugin-magnify-js/
Im little bit stuck on a logic.scenario is i have a slider where two images are shown at a time taking 50%-50% part of screen,here is the simple html of it,
<div class="zeus-slider zeus-default" >
<div class="zeus-block">
<div class="zeus-slide s-50"> <img src="slider/slider1.jpg" data-effect="slideRight" alt="" /> </div>
<div class="zeus-slide s-50"> <img src="slider/slider2.jpg" data-effect="slideRight" alt="" /> </div>
</div>
</div>
here every block contains two images i have shown only one.now i have trying to make it dynamic, but i didnt get any idea how it will work, so i created database with two tables, each for individual image in a single block.Both table have fields like simg_id(A_I),img_name,simg_path.
here its my php on slider page.
<div class="zeus-block">
<?php
$slider_slt=getResultSet('select * from slider_img_master1 ORDER BY simg_id');
if(mysql_num_rows($slider_slt))
{
while($slider_data=mysql_fetch_assoc($slider_slt))
{
?>
<div class="zeus-slide s-50"> <img src="slider/first/<?php echo $slider_data['simg_path']?>" data-effect="slideRight" alt="" /> </div>
<?php }
} ?>
<?php
$slider_slt2=getResultSet('select * from slider_img_master2 ORDER BY simg_id');
if(mysql_num_rows($slider_slt2))
{
while($slider_data2=mysql_fetch_assoc($slider_slt2))
{
?>
<div class="zeus-slide s-50"> <img src="slider/second/<?php echo $slider_data2['simg_path']?>" data-effect="slideRight" alt="" /> </div>
<?php }
} ?>
</div>
now the problem is when i try to fetch path of image in slider, images are not changing one by one on both half of screen.instead it showing like both images from from both table top, another two images from both tables below 1st both, and so on , so full page is covered with images.
I know this idea of creating two tables for getting two images at once is silly,but i could not think any better.if any one can suggest any better way, it would be so helpful.
Update:getResultSet is function for mysql_query.
if anybody interested i found an answer for above question.
<div id="slide1" >
<div class="zeus-slider zeus-default" >
<?php
$slider_str="select *from slider_img_master1 where simg_status='Active'";
$i=1;
$result=mysql_query($slider_str);
if(mysql_num_rows($result)>0)
{
echo '<div class="zeus-block">';
while($row=mysql_fetch_assoc($result))
{
if($i%2==1 && $i!=1)
{
echo '<div class="zeus-block">';
}
?>
<div class="zeus-slide s-50"> <img src="slider/<?php echo $row['simg_path'];?>" data-effect="slideRight" alt="" /> </div>
<?php
if($i%2==0)
{
echo '</div>';
}
$i++;
}
} ?>
</div>
<div class="clear"> </div>
<div class="next-block"> </div>
<div class="prev-block"> </div>
</div>
I am pretty new to php. Please excuse me if this is a foolish question.
I have added social share icons to my blog via php. In the main index page I added facebook, twitter and google plus share icons and in the single post I added some more icons.
How I implemented?
I created two php files social_main_index.php and social_single_post.php
Then in the main index template I added the code <? php include("social_main_index.php") ?>
In single post template I added the code <? php include("social_single_post.php") ?>
My Question
Can I create a single php file containing both codes and call any one of them specifically?
My code in social_main_index.php
<?php include_once("custom_css.php") ?>
<div class="social-single">
<!--Facebook Share-->
<div id="likebutton"><iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo rawurlencode(get_permalink()); ?>&layout=button_count&show_faces=false&width=100&action=like&font=verdana&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe></div>
<!--Google Plus Share-->
<div id="plusonebutton"><g:plusone href="<?php echo rawurlencode(get_permalink()); ?> "size="medium"></g:plusone></div>
<!--Twitter Share-->
<div id="twitterbutton"><script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script><div> </div>
</div>
</div>
My code in social_single_post.php
<?php include_once("custom_css.php") ?>
<div class="social-single">
<!--Facebook Share-->
<div id="likebutton"><iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo rawurlencode(get_permalink()); ?>&layout=button_count&show_faces=false&width=100&action=like&font=verdana&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe></div>
<!--Google Plus Share-->
<div id="plusonebutton"><g:plusone href="<?php echo rawurlencode(get_permalink()); ?> "size="medium"></g:plusone></div>
<!--Twitter Share-->
<div id="twitterbutton"><script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script><div> </div></div>
<!--Linkedin Share-->
<div id="linkedinshare"><script type="text/javascript" src="http://platform.linkedin.com/in.js"></script><script type="in/share" data-url="<?php the_permalink() ?>" data-counter="right"></script></div>
<!--Stumble Share-->
<div id="stumblebutton"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1"></script></div>
</div>
This is actually a pretty simple thing to do, and I recommend you read up on the manual when you get a chance. Just create a function that will return either bit of html:
function print_buttons($button_set) {
if ($button_set == "one") { //if the local variable for the function is the string "one", then paste the data below where the function is called
return '<div class="social-single">
<!--Facebook Share-->
<div id="likebutton"><iframe src="http://www.facebook.com/plugins/like.php?href='.rawurlencode(get_permalink()).'&layout=button_count&show_faces=false&width=100&action=like&font=verdana&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe></div>
<!--Google Plus Share-->
<div id="plusonebutton"><g:plusone href="'.rawurlencode(get_permalink()).'"size="medium"></g:plusone></div>
<!--Twitter Share-->
<div id="twitterbutton"><script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script><div> </div>
</div>
</div>';
}
else { //if the local variable is anything else, do the same thing, but with the below data instead.
return '<?php include_once("custom_css.php") ?>
<div class="social-single">
<!--Facebook Share-->
<div id="likebutton"><iframe src="http://www.facebook.com/plugins/like.php?href='.rawurlencode(get_permalink()).'&layout=button_count&show_faces=false&width=100&action=like&font=verdana&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe></div>
<!--Google Plus Share-->
<div id="plusonebutton"><g:plusone href="'.rawurlencode(get_permalink()).'"size="medium"></g:plusone></div>
<!--Twitter Share-->
<div id="twitterbutton"><script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script><div> </div></div>
<!--Linkedin Share-->
<div id="linkedinshare"><script type="text/javascript" src="http://platform.linkedin.com/in.js"></script><script type="in/share" data-url="'.the_permalink().'" data-counter="right"></script></div>
<!--Stumble Share-->
<div id="stumblebutton"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1"></script></div>
</div>';
}
}
And then to use it...
echo print_buttons("one"); //this will print the first group
echo print_buttons("anything else"); //this will print the second
Take note that this is a shoot in the dark, as I don't know what the functions you were echoing out and otherwise returned/did. If I did, I could say for certain this would work for you. I however do not, and thus the above.
To use this function, make sure it is included on the page it is being used in, just as the css above is included via include(). Example:
some_functions.php:
<?php
function the_function_above() { }
?>
And then...
The_page_above.php:
<?php
include("some_functions.php");
echo the_function_above();
?>