I have an album plugin (php) that creates thumbnails for my images in one page and when i click on images opens each image in a new page.
Is there a way to opening images on the same page of thumbnails?
This is my code of thumbnails:
<div class="thumbs">
<?php foreach (wppa_get_thumbs() as $tt) : global $thumb; $thumb = $tt; ?>
<img src="<?php wppa_thumb_url(); ?>" alt="*" />
<?php endforeach; ?>
</div>
and this is the code of specific photo:
<?php } else if (wppa_page('single')) { // if is showing a specific photo ?>
<a href="<?php wppa_photo_url(); ?>"><img src="<?php wppa_photo_url(); ?>" alt="<?php wppa_photo_name(); ?>" class="big" <?php echo wppa_get_fullsize(); ?> />
</a><br />
<?php } ?>
And this is the function that creates links:
// get link to photo
function wppa_photo_page_url($return = FALSE) {
global $thumb;
$url = get_permalink() . wppa_sep() . 'album=' . $_GET['album'] . '&photo=' . $thumb['id'];
if ($return) {
return $url;
} else {
echo $url;
}
}
I tried to remove the link code but does not work.
The act of opening a link in a new window is usually associated with the "target" attribute of an anchor. For example, this would put links in new windows:
text
But the code you've pasted above does not appear to include target attributes in , so I suspect the behaviour is controlled in your CSS, which you didn't include in your question.
Check your CSS files, and look for "target". The W3C has published documentation that describes how this works.
It's actually very easy to do using plain javascript's Image object. You can have a function that does something like this:
function load_image(image_path)
{
var image = new Image();
image.src = image_path;
return image;
}
You can pull the url to the image from the link that they click on.
Then, append that image to a hidden div you have and make it visible. If you're using jQuery:
var image = load_image("/path/to/your/image.jpg");
$(image).appendTo("#your-image-div");
$("#your-image-div").show();
This is untested, but should work.
You could use a jQuery plugin like Lightbox to pop the content dynamically over the current page.
Related
I have a WP site and I am trying to achieve the following. I need on 3 different pages a separate image in the footer.
I did find an answer how to do it the following way placing this code in the footer:
<?php
if(is_page(4)):
?>
<div class="images"><img src="url-image-location" alt="alt info" class="img-responsive"></div>
<?php endif; ?>
The above way works great but i'm lost on how to add it for the another page. I tried just repeating the above code again and changing the page and image url but then I lose styling from the rest of footer.
So question is, how do I add it a second time?
Thanks
What about using elseif and just change the image path variable so you won't loose styling? i assume your css is written for class.
<?php
$image_path = "imagepath";
if (is_page(4)) {
$image_path = "imagepath-4";
}
else if (is_page(5)) {
$image_path = "imagepath-5";
}
else if (is_page(6)) {
$image_path = "imagepath-6";
}
?>
<div class="images"><img src="<?php echo $image_path?>" alt="alt info" class="img-responsive"></div>
I am trying to achieve the below image:
Basically, I have set up ACF Gallery, and used the code below:
<?php $images = get_field('gallery'); if( $images ): ?> <!-- This is the gallery filed slug -->
<?php foreach( $images as $image ): ?> <!-- This is your image loop -->
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> <!-- Image Code -->
<?php endforeach; ?> <!-- This is where the image loop ends -->
<?php endif; ?> <!-- This is where the gallery loop ends -->
Which now lists all the images in the gallery. What I am looking for, is the first image to be full size, and the other 3 images to be thumbnails, like the image, which when clicked, change the full size image.
Anyone have any ideas?
EDIT:
Im open to another way of doing this
Normally I wouldn't post all of this, as it would require creating a lot of stuff, but luckily I just made something similar for work yesterday.
<?php $galleryImages = get_field('gallery'); ?>
<div id="largeGalleryImage">
<img src="<?php echo $galleryImages[0]['sizes']['gallery-full']; ?>" id="galleryImageLarge" />
</div>
<div id="galleryThumbs">
<?php $i = 0;
foreach($galleryImages as $galleryThumb){
$i++;
if($i==1){
$imgClass = 'active';
}else{
$imgClass = '';
}
echo '<img src="'.$galleryThumb['sizes']['gallery-thumb'].'" class="imageThumb imageNum'.$i.' '.$imgClass.'" picURL="'.$galleryThumb['sizes']['gallery-full'].'" />';
} ?>
</div>
<script type="text/javascript">
//Setup Gallery Clicks
$("#galleryThumbs .imageThumb").click(function () {
if ($(this).hasClass('active')) {
//do nothing
} else {
var newImage = $(this).attr('picURL');
$('#galleryImageLarge').attr('src', newImage);
$("#galleryThumbs .imageThumb").removeClass('active');
$(this).addClass('active');
}
});
</script>
In this example, "gallery-full" is a set custom image size for the large photo, and "gallery-thumb" is a set custom image size for my thumbnails.
The thumbnails have an attribute applied to them, called "picURL" and it houses the URL of the large image. The large image is auto-filled with the URL of the first image. Then, using jQuery, when a thumb is clicked, it changes the src value of the large image with the value of the thumbnail's "picURL".
It also gives the current thumbnail an "active" class, to allow for styling your current thumb.
I am creating a social website.I want to show all the details of registered users from the database in a list which includes their image and name.I want to display an image if the user has not provided the image.If the image has been provided by the user,sometimes it may get lost from database.At that time also i need to display a particular image.I have found that by using javascript method onerror(),we can check whether the image is loaded or not.I am unaware of its implementation.
My code sample is like this:
while($row_data = mysql_fetch_array($result_personal))
{
$row_photo = $row_data['acnt_profile_picture'];
<div class="feedstory" id="feedstory">
<img src="<?php if($row_photo!=NULL){echo $row_photo;}
else{?>images/no_image.png<?php }?>" id="image1" width="34" height="34" align="left" class="feedthumb" alt="photo"
onerror="imageError()"/>
</div>
}
My javscript method is like this:
function imageError()
{
document.getElementById("image1").src="images/no_image.png";
}
I need to display no_image.png if $row_photo is null or $row_photo is not loaded
You've said (in the comments)
if the variable is null,"no_image.png" is displaying.Bit if the image is not loaded,"no_image.png" is not been displayed
So it's not a path issue, there's something wrong with the imageError call.
The call would be right if you had an img element with the id "image1". But your img element doesn't have that id, and you haven't shown a different one that does.
If your goal is to show no_image.png in the img element that had the error, then:
Change your onerror attribute from:
onerror="imageError()"
to
onerror="imageError(this)"
And then change imageError to:
function imageError(img)
{
img.src="images/no_image.png";
}
Make sure you enclose your php code in php tags.
jQuery solution:
<?php
while($row_data = mysql_fetch_array($result_personal)) {
$row_photo = $row_data['acnt_profile_picture'];
?>
<div class="feedstory" id="feedstory">
<img src="<?php echo $row_photo ?>" width="34" height="34" align="left" class="feedthumb" alt="photo" />
</div>
<?php } ?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('img').error(function() {
$(this).attr({
src: '/images/missing-image.jpg',
alt: 'Sorry! This image is not available!',
style:'border: 1px solid #f00;'
});
});
});
</script>
Depending on whether or not your database structure is the same as mine, you can use this function, I put it inside my User class.
public static function ProfileImage($user_ID, $image_ID, $size)
{
global $http_r;
$image_URL;
if($image_ID != null)
$image_URL = $http_r ."/userfiles/images/". $user_ID ."/thumbnails/". $image_ID .".jpeg";
else
$image_URL = $http_r ."/template/images/noprofilepic.jpg";
?>
<img src="<?php echo $image_URL; ?>" class="profile-<?php echo $size; ?>">
<?php
}
Which is then used like the following: User::ProfileImage($user_ID, $image_ID, "small");
But, I have a seperate table for my images and I do not store image paths directly.
I'm have a wordpress installation where i have 2x custom fields, that both store images (or rather the urls for the images).
I then have a div that i want to display the images in. but i want to display the first image, then have some nice buttons that will scroll to the next image.
My code so far is below:
<div>
<?php
$front_cover = get_post_meta($post->ID, 'front_cover', true);
$back_cover = get_post_meta($post->ID, 'back_cover', true);
$artwork = $front_cover;
if ($back_cover === '') {
echo '<img src="'.$artwork.'" />';
} else {
echo '<img src="'.$artwork.'" />';
?>
<div class="artwork_controls">
Previous
Next
<span class="sliderPagination">1 of 3</span>
</div>
</div>
<?php } ?>
As you can see. my If statement checks if the back_cover has any content... if it doesn't it displays the front_cover only.
If the back_cover does have content it should display the front cover and then the buttons that the user clicks to load up the back cover.
My thinking was that i could get the 'previous' and 'next' buttons to dynamically change the $artwork variable, but i don't believe that's possible as the PHP would have already been processed?
This code could be completely wrong, but hopefully you can see what i'm trying to do?
<div>
<?php $front_cover = get_post_meta($post->ID, 'front_cover', true); ?>
<?php $back_cover = get_post_meta($post->ID, 'back_cover', true); ?>
<?php $artwork = $front_cover; ?>
<?php if ($back_cover === '') { ?>
<img src="<?php echo $artwork; ?>" />
<?php } else { ?>
<img id="imgA" src="<?php echo $artwork; ?>" />
<img id="imgB" src="<?php echo $back_cover; ?>" style="display:none;"/>
<div class="artwork_controls">
<span class="sliderBtnPrev" onClick="document.getElementById('imgA').style.display='none';document.getElementById('imgB').style.display='';">Show B</span>
<span class="sliderBtnNext" onClick="document.getElementById('imgB').style.display='none';document.getElementById('imgA').style.display='';">Show A</span>
</div>
<?php } ?>
</div>
One way would be to do AJAX calls and fetch images upon clicking the "Previous" and "Next" buttons.
However you can just put all your images in the final html and do all the rest with javascript and some css.
So if you just put the two images in the html, lets say they have ids "front-image" and "back-image" so you've got this
<img id="front-image" src="imgs/front-cover.jpg"/>
<img id="back-image" src="imgs/back-cover.jpg" style="visiblity: hidden"/>
Notice the style="visibility: hidden". From than on you can have onClick handlers on your Previous and Next buttons which just set the visibility of the two images.
clickHandlerPrev() {
document.querySelector("#front-image").style.visibility = "";
document.querySelector("#back-image").style.visibility = "hidden";
}
clickHandlerNext() {
document.querySelector("#front-image").style.visibility = "hidden";
document.querySelector("#back-image").style.visibility = "";
}
Then your buttons would look like this
Previous
Next
Though if I'm getting your goal right, I think your buttons are better named simply "Front cover" and "Back cover" since you're not iterating over lots of images, but switching just those two.
I am using a wordpress theme that has a custom post type called "link" which simply produces a post where the title links to an outside link you specify. It also includes some text in the body of the post. I would like to also be able to display an image. Right now it is not showing the image.
Here is the code:
elseif ( has_post_format( 'link' )) {
if(get_post_meta($post->ID, '_format_link_url', true)!=''){
$link = get_post_meta($post->ID, '_format_link_url', true);
}else{
$link = '';
}
?>
<h2 class="entry-title">
<a href="<?php echo $link; ?>" target="_blank" title="Follow this link">
<?php the_title(); ?>
</a>
</h2>
<p>
Is there anything I can add to make it display an image as well as text?
Thanks!
I can't see anywhere on this example where you are using an tag to insert an image. The img tag has two required attributes, src and alt. Src is the path to your image, whereas alt is the alternate text for the image. So:
<img src="images/myImage.png" alt="This Is My Image"/>
Hope that helps!