Tagged: gallery, single.php
-
AuthorPosts
-
January 30, 2016 at 10:20 pm #575102
I want to be able to add a gallery (with preview) to a single posts page in my child theme.
The single posts will (in effect) be product listings which will be both admin and user-submitted (via a frontend form).The gallery will use the images (if any exist) that are added to each post by means of custom fields.
I’m guessing I need relevant php to add the gallery rather than shortcodes (please can you tell me what to add?) but is it possible to get the images with something like <?php the_field(‘cattery_img2_wide’); ?> ?Thanks!
January 31, 2016 at 3:32 am #575134Hey brian7454!
That would take a lot of time and code to implement so it would have to be considered custom work. It would be best to hire a freelancer to help you out with this customization.
Best regards,
ElliottJanuary 31, 2016 at 11:17 am #575227Well, you might not be willing to help with custom coding but can you at least tell me how to manually add a gallery with preview to single.php? That gives me a starting point..
January 31, 2016 at 11:54 am #575269Hey!
You could use the Enfold gallery as a shortcode, in your custom template you’d include something like:
echo do_shortcode("[av_gallery ids='314,313,745' style='thumbnails' preview_size='portfolio' crop_big_preview_thumbnail='avia-gallery-big-crop-thumb' thumb_size='portfolio' columns='5' imagelink='lightbox' lazyload='avia_lazyload' custom_class='']");
Whereas “314,313,745” would be the attachments (ID) the gallery will show.
Cheers!
JosueJanuary 31, 2016 at 10:23 pm #575440Well, that brings up 3 thumbnails that can be clicked. Unfortunately, I can’t see from the code how to add the preview, nor how I would specify that the images shown should only be those from the current custom post.
As I said earlier, I needed something I could add custom fields to (these would contain the images). Having to try and work it out for myself, I tried the cheat’s approach and pasted the following into my single-baker.php. It does part of what I want.
I’m just deleting the code while I edit it.. will post it again in a second
- This reply was modified 8 years, 10 months ago by brian7454.
January 31, 2016 at 11:22 pm #575448Further to my previous…no idea why the code won’t paste properly. Tried backticks, clicking ‘code’ but it outputs like this.
I looked at the source code from the shortcodes page and copied the html and then added the image fields. For now I have no idea why each gallery item has 3 image links (I can see one is the thumbnail) so for now I’m probably doing it wrongly. However, this gives me a gallery with preview thumbnails under. This is what I used……
<div class='avia-gallery avia-gallery-99 avia_lazyload avia_animate_when_visible avia-builder-el-12 el_after_av_textblock avia-builder-el-last'>
<a>' data-onclick='1' title='Click to see full-size' ><span class='avia-gallery-big-inner'> <img width='845' height='321' />' title='image two' alt='alt text' /></span></a>
<div class='avia-gallery-thumb noshow'>
<a>' data-rel='gallery-99' data-prev-img='<?php the_field('baker_img1a'); ?>' class='first_thumb lightbox ' data-onclick='1' title='<?php the_field( 'baker_name' ); ?>' itemprop="contentURL" ><img />' width='80' height='80' title='<?php the_field( 'baker_name' ); ?>' alt='<?php the_field( 'baker_name' ); ?>, <?php the_field( 'postal_town' ); ?>' /></a>
<a>' data-rel='gallery-99' data-prev-img='<?php the_field('baker_img2a'); ?>' class='lightbox ' data-onclick='2' title='<?php the_field( 'baker_name' ); ?>' itemprop="contentURL" ><img />' width='80' height='80' title='<?php the_field( 'baker_name' ); ?>' alt='<?php the_field( 'baker_name' ); ?>, <?php the_field( 'postal_town' ); ?>' /></a>
<a>' data-rel='gallery-99' data-prev-img='<?php the_field('baker_img3a'); ?>' class='lightbox ' data-onclick='3' title='<?php the_field( 'baker_name' ); ?>' itemprop="contentURL" ><img />' width='80' height='80' title='<?php the_field( 'baker_name' ); ?>' alt='<?php the_field( 'baker_name' ); ?>, <?php the_field( 'postal_town' ); ?>' /></a>
<a>' data-rel='gallery-99' data-prev-img='<?php the_field('baker_img4a'); ?>' class='lightbox ' data-onclick='4' title='<?php the_field( 'baker_name' ); ?>' itemprop="contentURL" ><img />' width='80' height='80' title='<?php the_field( 'baker_name' ); ?>' alt='<?php the_field( 'baker_name' ); ?>, <?php the_field( 'postal_town' ); ?>' /></a></div></div></div>
This gives me a gallery in single.php with the images called from custom fields. It seems to work, in that respect.
However, if I put my mouse over the thumbnails and the preview image changes, the formatting is crap because if the gallery includes a mix of images of different sizes, the preview screen for all images takes the size of the tallest one, leaving acres of whitespace under any following landscape format images. My original intention was to allow users to upload up to 5 images……… but that means some will upload 5, some just 1 and some 0. That would make the thumbnails look silly, so the only solution I can see is to hide them with css (I can see they have to be on the page in the first place for the gallery to work). Doing that, the lightbox opens if the ‘preview’ image is clicked and the correct images can be cycled through.
But I still come back to the thing I knew would be the problem;
I only want the gallery (and it’s entire containing div) to be displayed if it the specific post actually contains images. Something like ‘if imagefield1 or imagefield2 contain a value/image, then show…otherwise hide’.For someone who knows even remedial php I’m pretty sure that’s child’s play to resolve. Unfortunately, I know nothing, which was why I was asking for a little help here. Can you tell me what I need to do?
- This reply was modified 8 years, 10 months ago by brian7454.
February 5, 2016 at 11:17 pm #578836Hi!
we’ve already given you a starting point and now you need to work it out by yourself or hire a freelance developer for this job, as it would be considered as custom work (see our support policy).
Cheers!
AndyFebruary 6, 2016 at 1:33 am #578893Wow, what a reply.
I asked what html I needed to add a gallery to a php template so that I can add a post’s images to it. The “starting point” given was to paste in a shortcode, and even a thumbsucking moron like me knows I can’t add my field data to that. So, as a “starting point” it ranks up there along with “Why are you asking me?”
The actual solution I employed and which could have been (but wasn’t) suggested in 12 words (“open a gallery page and copy the relevant source code with firebug”) left me almost there but still in the dark on one point. How to hide an empty gallery. I asked how to do it because I didn’t have a clue. After searching online (not actually knowing what I was looking for) I found the solution after getting on for a day and a half. It took about 10 seconds to type the code.
The “custom work” you refer to above which I should pay someone for or “work out for yourself” (why not just say “we’ve got the money, now fuck off?”) extends to two simple lines:
<?php if( get_field(‘name_of_field’) ): ?>
add gallery container here…
<?php endif; ?>Is your support so lacking that you think it’s sufficient to tell me to use a shortcode to do something it won’t do (instead of just saying what to copy) or can’t be bothered to write two simple and bog standard lines of php? Or do you just not know the answers if they’re not written in kiddie crayon above your monitors?
I paid for this theme on the grounds that I could always ask questions if I needed a little help, rather than go to the sites where this, avada and god knows what else are free (and up to date as of 2 days ago) – but without support. Guess that makes me dumb then.
February 7, 2016 at 10:23 pm #579259Hi!
Support is limited to theme-related questions or requests, if you read your replies carefully you’ll note you’re basically asking for support regarding a third-party plugin (ACF) + WordPress/PHP related questions, hence the answers you’re getting.
From the register page:
First of all, please note that theme support is not a requirement for Themeforest authors, but we do it nevertheless, simply because we like to see our customers happy. We will answer as soon as possible to any questions asked, but please be aware that there are limits to the scope of our theme support. Support covers installation of the theme, issues arising from using any of the theme features and of course bug fixes and feature updates.
We cant help with installation of WordPress itself, 3rd party plugins that were not part of the theme package or heavy theme customization.
Cheers!
Josue -
AuthorPosts
- You must be logged in to reply to this topic.