Leveraging the facts that:
- JIG can detect and show images attached to a post automatically...
- You can create a PHP template tag and place it anywhere in the theme...
It's clear that if you use plenty of pictures throughout your posts, an automatic gallery at the beginning or end of articles is a good idea.
Add a gallery of attached images automatically
- Locate the file of your theme that's for showing single posts, products etc. Depending on your theme and custom post type, it may be different but it's usually the /wp-content/themes/Avada/single.php file. It's recommended to use child themes though.
- Find the line that contains:1<?php the_content(); ?>
- Add this where you need the gallery:1<?php get_jig(); ?>
- Some posts might not have images, so hide the JIG error message: "There are no photos with those IDs or post X does not have any attached images!" Add this to JIG settings > General tab > Custom CSS setting:123.jigErrorMessage{display: none;}
Pro tip: Create a related posts gallery at the bottom of your articles
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php $post_terms = get_the_terms(get_the_ID(), 'category'); if(!empty($post_terms){ $recents_filter_terms = array(); foreach ($post_terms as $term){ $recents_filter_terms[] = $term->slug; } $recents_filter_terms = implode(',',$recents_filter_terms); get_jig(array( 'max_rows' => 1, 'orderby' => 'rand', 'recent_posts' => 'yes', 'recents_filter_tax' => 'category', 'recents_filter_term' => $recents_filter_terms, 'post_ids_exclude' => get_the_ID() )); } ?> |