FlexSlider and Fancybox - php

i'll try to build a slider with FlexSlider
the images in the slider should be viewed 'onclick' with Fancybox.
my code for now:
$(".slides li").fancybox();
$('#flex1').flexslider({
animation: "slide",
animationLoop: false,
itemWidth: 179,
itemMargin: 0,
minItems: 4,
maxItems: 4,
controlNav: false,
pauseOnHover: true,
slideshowSpeed: 5000,
keyboardNav: true,
slideshow: false,
});
in document ready
the HTML / PHP looks like this:
<div class="flexslider" id="flex1">
<ul class="slides home_single_item">
<?php
$handle=opendir ("pics/");
$i=0;
while ($datei = readdir ($handle)) {
$i++;
if($datei != "." && $datei != ".."){
echo '<li>';
echo '<img class="fancybox" src="pics/'.$datei.'" width="179px" height="224px" />';
echo '</li>';
}
}
closedir($handle);
?>
</ul>
</div>
If i click on a image, it where displayed as an small picture and it disappears from my gallery list.
Are there any issues known between Flexslider and Fancybox ?
Anyone has a solution ?
Thanks ;)

There is not conflict or whatsoever.
What you are doing is binding fancybox to the list element
$(".slides li").fancybox();
...so fancybox moves the content of li (the img tag) to the box. Since you have these properties in your img tag:
width="179px" height="224px"
... the image is small in fancybox.
At this point, fancybox is handling the content as inline content so the img tag is returned after closing fancybox with the css property display: none; (that is the expected behavior.)
What you have to do is to change this part of your php and add an a tag to target the image to be opened in fancybox like :
if($datei != "." && $datei != ".."){
echo '<li>';
echo '<a href="pics/'.$datei.'" class="fancybox">';
echo '<img src="pics/'.$datei.'" width="179px" height="224px" />';
echo '</a>';
echo '</li>';
}
... notice that we moved the class="fancybox" from the img tag to the a tag. Then bind fancybox to that a tag in your script like :
$(".slides a").fancybox();
or better
$(".slides a.fancybox").fancybox();
or much simpler and better
$("a.fancybox").fancybox();

Related

PHP specific images not aligning

I'm trying to make all images be displayed side by side with the following code:
<div id = "all-container">
<?php
$dir = "images/";
$arr = scandir($dir);
foreach ($arr as $img) {
if ($img != '.' && $img != '..') {
echo "<div class = 'img-container'><img class = 'image' src = 'images/$img'></div>";
}
}
?>
</div>
This is class 'img-container' in CSS:
.img-container {
float: left;
display: inline-block;
}
Apparently, this seems to work when I set the image source to some random picture from the internet.
But when I use my own images, they're still displayed top to bottom.
The images I'm using are the Windows 7 Sample Pictures (1024 x 768 in size, JPG).
I tried many times, and if I just change the source of the image, it seems to work.
Is there something wrong with my code?
you should nest img tags like below:
<div class = 'img-container'>
<img class = 'image' src ='http://lorempixel.com/200/200'>
<img class = 'image' src ='http://lorempixel.com/200/200'>
</div>
But your code will create div tag with img-container class each time it repeats;
you will need to print out :
<div class = 'img-container'>
before foreach and
</div> /*end of img-container div tag*/
after it.

Positioning text under an image using echo

I am using php to loop through and display all images from a directory. This works, however I want to add the image name underneath each of the images. I am struggling to get the text to center underneath it, as it seems to just place it next to it and appears to be in its own column separate to the image.
How do I go about fixing this? From research I've done the general solution seems to be placing them in a div together, I haven't done much php before but am I able to just stick the two echo statements inside of a div tag?
<div id="contentClothing">
<?php
function hoodie() {
$dir = 'images/clothing/hoodies/small/';
$files = scandir($dir);
$images = array();
foreach($files as $file) {
if(fnmatch('*.png',$file)) {
$images[] = $file;
}
if(fnmatch('*.jpg',$file)) {
$images[] = $file;
}
}
foreach($images as $image) {
echo '<img src="images/clothing/hoodies/small/'.$image.'"width=15% height=20% hspace=2% vspace=2% data-big="images/clothing/hoodies/large/'.$image.'" />';
echo '<span>'.$image.'</span>';
}
}
?>
</div>
Here is the css
#contentClothing {
padding-bottom: 5%; /* Height of the footer element */
margin-left: 15%;
}
span {
text-align: center;
}
This is how it looks http://puu.sh/m8Zh0/6b0da6ec03.png
Instead of <span>, use <p> tag. Wrap the whole image and text inside <div> tag and apply your styles to it.
// your code
foreach($images as $image){
echo '<div style="text-align:center; float:left; clear:right;">';
echo '<img src="images/clothing/hoodies/small/'.$image.'"width=15% height=20% hspace=2% vspace=2% data-big="images/clothing/hoodies/large/'.$image.'" />';
echo '<p>'.$image.'</p>';
echo '</div>';
}
// your code

Get the featured image url of clicked post

How can I display the featured image of a post in a modal along with it's content.
With the help of a few online threads on similar issues, I tried this:
<?php
if ( has_post_thumbnail()) {
echo '<a href="' . get_permalink($post->ID) . '" >';
the_post_thumbnail('my_feature_image', array( 'class' => "someName" ));
echo '</a>';
}
?>
Which unfortunately returns the same featured image for all posts.
On the same header.php where the modal is found, the following is there (above the modal divs):
//on the homepage... check for the post URL...
//do we have a custom permalink incoming....
$perma = false; if (isset($wp_query->query_vars['phpost_slug'])) #WHFIX 24/03/2015:
$perma = $wp_query->query_vars['phpost_slug'];
if($perma){
//we don't want to return a 404
$wp_query->set( 'is_404', false );
$phid = get_page_by_path($perma, OBJECT, 'post');
$postvote = get_post_meta($phid->ID, 'epicredvote' ,true);
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $phid->ID ), 'single-post-thumbnail' );
$pluginfeat = get_post_meta($phid->ID,'phog',true);
$desc = get_post($phid->ID)->post_content;
link to site: https://goo.gl/30a3QQ [Click on the post's row to open the modal.]
UPDATE
I tried removing the anchor tags as well as the classes like this and it still isn't working:
<?php
if ( has_post_thumbnail()) {
the_post_thumbnail();
}
?>
The element you are changing is only the html wireframe for the onclick handlers to populate, the problem is, it didnt include a image on the original so you need to add that functionality. something like this should work (add to your footer)
var eventTargets=document.querySelectorAll('.hunt-row');
[].forEach.call(eventTargets, function(t){
t.addEventListener('click', function(){
console.log('clicked');
var img= this.querySelector('img').src;
//bind new src to modal thumb, this is not ideal as there is only a class rather than a id...
document.querySelector('.modal-thumb').src= img;
}, false);
});
Of course, im not sure how nice it will play with the other click handlers, you may need to remove the default and write your own to populate the model box onclick.

PHP: Add html icons to a script

I need to add the same icon to each of the li class that are generated automatically by a PHP script that Im using in a customized widget, in a Wordpress site.
This is the script Im using in a wordpress widget to display some child pages.
<?php
$ancestor_id=24;
$descendants = get_pages(array('child_of' => $ancestor_id));
$incl = "";
foreach ($descendants as $page) {
if (($page->post_parent == $ancestor_id) ||
($page->post_parent == $post->post_parent) ||
($page->post_parent == $post->ID))
{
$incl .= $page->ID . ",";
}
}?>
<ul>
<?php wp_list_pages(array(
"child_of" => $ancestor_id,
"include" => $incl,
"link_before" => "",
"title_li" => "",
"sort_column" => "menu_order"));?>
</ul>
The code for the icon (has already a class asigned) that I need to be used is..
<img class='sideicons' src="http://accountabletest.com/wp-content/uploads/2013/12/iconSidebar1.jpg" alt="" >
How can I make each <li> generated to include the same icon?
use css, the rules you need are list-style-type and list-style-icon
Sounds like to do it in PHP would probably be more trouble than it's worth... How about javascript or jquery?
$('li').each(function(i,el){
$(this).prepend('<img src="path/to/image.ico" />');
})
If you need to change the existing source of an image, target with something like $('li img')
Change .prepend() to attr('src','your/new/image.jpg')
Why you are not using CSS? It is easier way to do. just assign a class to your ul and add a background image to li tags.
like:
<ul class="list">
<?php wp_list_pages(
array(
"child_of" => $ancestor_id,
"include" => $incl,
"link_before" => "",
"title_li" => "",
"sort_column" => "menu_order"
)
);?>
</ul>
<style>
ul.list li {
background: url(http://accountabletest.com/wp-content/uploads/2013/12/iconSidebar1.jpg) no-repeat left center;
padding-left: 10px;
}
</style>

Unable to get animations to work correctly in jQuery

I just recently started learning jQuery. To help me learn, I started redesigning this website. The problems I have at the moment are:
Once a thumb image is clicked and the main post loads; after closing the main post and when hovering over the thumbs again, the title and post information no longer fade in above and beside the thumbs.
When hovering over a thumb image for the first time, you should notice that it hides everything (including itself) and then shows itself again, this gives the illusion that it flickers. How can I stop this?
Here is the .js file containing the jQuery code:
$(".post").hover(
function () {
$(this).children(".post_title, .post_info").stop(true).fadeIn();
$(this).children(".link-to-post").stop().show();
$(".post").stop().fadeTo(0,0.2);
$(this).fadeTo(300,1);
},
function () {
$(this).parent().find(".post_title, .post_info").stop(true).hide();
$(this).parent().find(".link-to-post").stop().hide();
$(".post").stop().fadeTo(300,1);
});
$(".cover-img").click(function(){
$("#main-post").fadeIn(1000);
$.post("inc/fullpost.php", {postid: $(this).data('postid')},
function(output){
$("#gotpostid").html(output).show();
}).fail(function(x,y,z){
$("#gotpostid").html(x + "<br />" + y + "<br />" + z)
});
$('.post').fadeTo(0,0);
});
$('input[name=close]').click(function(){
$(this).closest('#main-post').hide();
Each thumbnail is within its own class:
// Retrieve all active posts order by lastest first
$resultarray = retrieve_active_posts();
echo '<div id="content-wrap">';
foreach($resultarray AS $value){
$filename = substr($value['img_file_name'],9);
$cat_id = $value['cat_id'];
echo '<article class="post">';
echo '<div class="post_title">' . stripslashes(stripslashes($value['post_title'])) . '</div>';
echo '<div class="post_info">' .
'Category: ' . $cat_name = get_cat_name($cat_id) .'<br />'.
'Year: ' . $value['post_year'] .'<br />'.
stripslashes($value['post_desc']) .'<br />'.
'</div>';
echo '<div class="link-to-post">Click to view</div>';
echo '<img class="post-thumb" src="img/thumb_/'.$filename.'" alt="MJbox Michael Jackson memorabilia thumbnail" data-postid="'.$value['post_id'].'"/>';
echo '<img class="cover-img" src="img/post-bg-1.png" alt="test" data-postid="'.$value['post_id'].'"/>';
echo '</article>';
}
echo '</div>';
I'll have another go :-)
I've looked on the Google Developer Tools and it looks like this is the problem...
$('.post').fadeTo(0,0);
It is leaving the opacity attribute as 0. When I override this in developer tools, the popups show again. Try changing it to:
$('.post').fadeOut;
or even
$('.post').hide();
Should do the trick.
I'm pretty sure I have the answer to the other problem:
You have two animations. You are fading all of the .post items out and then fading $(this) back in again. You need this solution:
$(".post").hover(
function () {
$(this).children(".post_title, .post_info").stop(true).fadeIn();
$(this).children(".link-to-post").stop().show();
$(this).siblings.().stop().fadeTo(0,0.2);
},
This will fade out only the other ones so you don't have to fade $(this) back in again!
Fingers crossed!
I have tested this. It fixes both problems and also stops the browser going to the top of the page when you click one of the thumbs.
Here is the complete jQuery code
$(document).ready(function(){
$(".fancybox").fancybox();
$("#login").click(function(){
$("#searchform").hide();
$("#loginform").fadeIn('3000','swing');
});
$("#search").click(function(){
$("#loginform").hide();
$("#searchform").fadeIn('3000','swing');
});
$(".post").hover(
function () {
$(this).children(".post_title, .post_info").stop(true).fadeIn();
$(this).children(".link-to-post").stop().show();
$(this).siblings().stop().fadeTo(0,0.2);
},
function () {
$(this).parent().find(".post_title, .post_info").stop(true).hide();
$(this).parent().find(".link-to-post").stop().hide();
$(".post").stop().fadeTo(300,1);
});
$(".cover-img").click(function(e){
e.preventDefault();
$("#main-post").fadeIn(1000);
$.post("inc/fullpost.php", {postid: $(this).data('postid')},
function(output){
$("#gotpostid").html(output).show();
}).fail(function(x,y,z){
$("#gotpostid").html(x + "<br />" + y + "<br />" + z)
});
$('.post').fadeOut();
});
$('input[name=close]').click(function(){
$(this).closest('#main-post').hide();
});
});
Just cut and paste this in place of your code.
Chris
This is for your first problem.
Try doing ...
$(".cover-img").click(function(e){
e.preventDefault();
.... rest of your code
This prevents the default behaviour of the browser to follow the link. This may solve your first problem but should be in there anyway with click events.

Categories