Support » Plugin: Meow Gallery (+ Gutenberg Gallery Block) » Convert Gallery?

  • Resolved frgtech

    (@frgtech)


    Hi,
    I’ve been trying out different galleries to to improve on the default supplied by WordPress and I like that it’s lightweight and doesn’t make itself dependent.

    Being new to WordPress I might be missing something but it seems that every gallery I try I have to recreate the gallery from scratch by going to my library and hand selecting every image from scratch. I can’t create a gallery in my media library and then access it with different plugins or edit it as its own entity that could be used or updated in multiple places.

    When trying your gallery I tried to cheat a bit by creating a small gallery then inspecting the shortcode and adding image ids to it. Apparently that is not an option and I’m back to being frustrated. 😛

    The other shortcode I tried to hack was to add captions by inserting captions=”true” inside the block but that didn’t work either. (Following this)

    Anyway, maybe from the supplied link you can get an idea of what I’m after. We are a tackle shop and do a daily fishing report. I want to display pictures of customers with their proud catches, (with a caption) and add to it as we go. My problem is I just inherited this blog that goes back to 2011 and there is a huge media library to sift through to collect all these images. Since I’ve done this already using the built in gallery, I have the list of image IDs I want to use.

      Can I build a gallery with a list of image ids?
      Can I sort a gallery by date?
      If I can’t sort, is there a better option when adding new images than to drag images one by one from the bottom of a gallery to the top?
      Can I add captions?
      Can I set the image link to the attachment page?

    Thank you for any insight you might impart.

    • This topic was modified 1 month ago by  frgtech.

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author Jordy Meow

    (@tigroumeow)

    Can I build a gallery with a list of image ids?

    Definitely. Normally mentioning the ids= in the shortcode works.

    Can I sort a gallery by date?

    By default, WordPress orders stuff using their IDs which is, more or less (but not exactly) the added date. More information here: https://meowapps.com/meow-gallery-tutorial/#Order_Sort. Modifying the order_by_taken_date I have given as an example would be the solution, I think.

    Can I add captions?

    Yes, by adding the caption parameter to the shortcode and set it to true (or 1). Have you tried? Of course, you would need an actual caption built into your Media entries.

    Can I set the image link to the attachment page?

    Yes, that’s the link attribute.

    It seems like the Gallery doesn’t work at all for you though, are you sure another gallery (maybe built-in in your theme) takes over?

    Thank you Jordy for getting back.

    I was able to sort out most of my issues already. I still had no luck with editing the shortcode, but I was able to convert my wordpress gallery to the Meow gallery once I found the option. I think some of the troubles was due to having Envira gallery still installed from when I tried it. I will try hacking the shortcode again now that I removed that.

    I created 2 more galleries from scratch and had zero issues so I’m trilled that I wouldn’t have to repeat that process should I ever need to remove Meow gallery. (not likely) The 2 galleries I created in Envira were lost of course when I removed it.

    I love this gallery and glad I was able to sort my issues out. I was able to get my captions and attachment links working, so I’ll try your suggestions on sorting by date and see how that goes.

    By default, WordPress orders stuff using their IDs which is, more or less (but not exactly) the added date.

    What I have found is when I create a wordpress gallery, it orders them in the order I added them to the gallery. The last image I add is the last image displayed. When I add to the gallery later, it always put new images at the bottom even though the newest images are at the top and I end up having to painstakingly drag them to the top since the galleries are large. (hopefully the shortcode will work now and I can just reorder that way if needed)

    My question on your sort function is if I need to trigger it somehow after adding new images, or will it auto-sort accordingly?

    Lastly, thanks for the wonderful software!

    Hi again,
    I’m not sure if I found a bug or did something wrong. Under the main admin menu there was an option to hide the main menu and have it sorted inside the settings menu. I tried setting this option and it complained about something which I assumed meant it was a pro version feature and ignored it.

    Problem is, it removed the menu from either places and I couldn’t get it back. I went ahead and installed another one of your plugins and now everything has returned to normal, but something definitely went wrong there.

    Cheers

    Plugin Author Jordy Meow

    (@tigroumeow)

    Hi 🙂

    About the menu disappearing, that’s normal if you choose to hide the Meow Apps Menu in the dashboard. The only way to get it back is to indeed, install another Meow Apps plugins (that will reset this option), or to go in General Settings, and there is an option to re-display the Meow Apps menu.

    About your question:

    My question on your sort function is if I need to trigger it somehow after adding new images, or will it auto-sort accordingly?

    The sort function will be applied automatically, always, before displaying the gallery on your website, so you don’t need to think about it. Once you have added the code for that “sort”, it’s always applied, you can remove/add/move images, but the sort will be always performed.

    frgtech

    (@frgtech)

    Thanks Jordy,
    I might be a bit out of my depth with the sort function, so for now I’ll just move the images manually. I do have some bash scripting experience but I’m not comfortable at all with php yet. (and wordpress’s inner workings) I’ll study some more so I can ask smarter questions if I can’t figure it out on my own.

    My more immediate issue is the gallery borders are not displaying properly. Borders are being cut off for some reason. Everything looks fine when editing the page, but not once published.

    Justified layout cuts off right border:
    https://fishingreport.friscorodandgun.com/image-galleries/surf-fishing/

    Tiles layout cuts off right and bottom borders:
    https://fishingreport.friscorodandgun.com/image-galleries/weather-events/

    Are you able to discern if this is a gallery or a theme issue?

    Thanks

    Plugin Author Jordy Meow

    (@tigroumeow)

    Those borders are added by your theme. You will need Custom CSS to remove the borders and the paddings. You could add this through the Customizer in your admin:

    img[class*="wp-image-"] {
        border: none;
        padding: 0px;
    }

    That will work 🙂

    Worked a charm and I also was able to get Meow Lightbox working except on the one page I didn’t want to use it so I could take comments on the pictures.I’ll try my hand at sorting soon as well.

    Thank you for the excellent products and helpful support!

    Plugin Author Jordy Meow

    (@tigroumeow)

    Thanks so much! Don’t hesitate to leave a few reviews for the Gallery and Lightbox, they need them 🙂

    If you would like to disable the Lightbox on specific pages, you can use the “Anti Selector” in the Settings. For example, for your Surf Fishing page, you could use this part:

    <article id="post-12450" class="post-12450 page type-page status-publish hentry">

    What interests us is the id “post-12450”, as it is unique. Just drop “post-12450” in the “Anti Selector” and the Lightbox will be disabled on this page 🙂

    Thanks for that, but I was trying to say that I got it working. After re-reading my post I can see it can be read many ways. 😛

    I used #post-12090 (for my Wall of Fame page) and it worked, but I’m certain your code is much more pinpoint so I’ll update it accordingly.

    I did also take the plunge on sorting and it is working as well, but only on my Wall of Fame gallery. If I change the a-b order, my images sort accordingly ascending or descending. For some reason it’s not working on my surf fishing or weather galleries though. I feel like I’ve bugged you enough so am still trying to sort it myself, but I’ll post my code just in case. 😉

    Will certainly do reviews for all that I use.
    Thanks!

    // Meow Gallery Sort Options
    // https://meowapps.com/meow-gallery-tutorial/#Order_Sort
    
    class My_Custom_Order_For_Meow_Gallery
    {
    	public $data;
    	
    	public function __construct() {
    		add_filter( 'mgl_sort', array( $this, 'my_mgl_sort' ), 25, 4 );
    	}
    
    	function order_by_taken_date( $id_a, $id_b ) {
    		// We get the information for each id we need to compare
    		$data_a = $this->data[$id_a];
    		$data_b = $this->data[$id_b];
    		// We return the result of the comparison on the created timestamp (taken date)
    		return $data_a['meta']['image_meta']['created_timestamp'] > $data_b['meta']['image_meta']['created_timestamp'];
    	}
    	
    	function order_by_title( $id_a, $id_b ) {
    		// We get the information for each id we need to compare
    		$data_a = $this->data[$id_a];
    		$data_b = $this->data[$id_b];
    		// We return the result of the comparison on the title
    		return strcmp( $data_b['meta']['image_meta']['title'], $data_a['meta']['image_meta']['title'] );
    	}
    
    	function my_mgl_sort( $ids, $data, $layout, $atts ) {
    		// Data contains metadata about the media (use printf on it to understand its structure)
    		$this->data = $data;
    		
    		// The usort function will order the $ids depending on a function.
    		// For fun, we pick a different function for the Tiles and Masonry layouts only.
    		if ( $layout === 'masonry' )
    			usort( $ids, array( $this, "order_by_title" ) );
    		else if ( $layout === 'tiles' )
    			usort( $ids, array( $this, "order_by_taken_date" ) );
    		return $ids;
    	}
    }
    
    new My_Custom_Order_For_Meow_Gallery();

    Edit:
    Looks like I might need to sort by post date if possible. Not all my images have the created_timestamp files populated. Open to other suggestions as well.

    • This reply was modified 2 weeks, 6 days ago by  frgtech.
    • This reply was modified 2 weeks, 6 days ago by  frgtech.
    Plugin Author Jordy Meow

    (@tigroumeow)

    I am sure you can do it ^^ Indeed, the

    created_timestamp

    might not be present. You might want to use the

    post_date

    instead, but I don’t think it’s part of this meta, but the “post” information for this media. So maybe like:

    $post_info = get_post( $id_a );
    // Compare using $id_a->post_date

    Thanks,
    Looks like I have more studying to do. 😛

    I guess I still have a way to go. I can’t get this working.

    I can see the order and orderby options in the standard gallery shortcode, but they aren’t working here. I’ve never worked with an object oriented language before and wordpress is still new so it gets overwhelming quickly and I get lost.

    Can you give me a hint to get on the right track?

    Plugin Author Jordy Meow

    (@tigroumeow)

    Hi @frgtech,

    As an ordering function, please use this:

    function order_by_upload_date( $id_a, $id_b ) {
    	// We get the information for each id we need to compare
    	$post_a = get_post( $id_a );
    	$post_b = get_post( $id_b );
    	// We return the result of the comparison on the created_timestamp
    	return strcmp( $data_b->post_date, $data_a->post_date );
    }

    This works 🙂

    Thanks so much Jordy, I can now see where I was going wrong before.

    This indeed changes the order, but it’s still not ordered properly according to the day published(post_date). The dates are so wildly distributed that I’m not sure I can see a pattern of why it’s not working.

    Does this look correct to you for a tiles gallery?

    class My_Custom_Order_For_Meow_Gallery
    {
    	public $data;
    	
    	public function __construct() {
    		add_filter( 'mgl_sort', array( $this, 'my_mgl_sort' ), 25, 4 );
    	}
    
    	function order_by_taken_date( $id_a, $id_b ) {
    		// We get the information for each id we need to compare
    		$data_a = $this->data[$id_a];
    		$data_b = $this->data[$id_b];
    		// We return the result of the comparison on the created timestamp (taken date)
    		return $data_a['meta']['image_meta']['created_timestamp'] > $data_b['meta']['image_meta']['created_timestamp'];
    	}
    
        function order_by_upload_date( $id_a, $id_b ) {
    	    // We get the information for each id we need to compare
    	    $post_a = get_post( $id_a );
    	    $post_b = get_post( $id_b );
    	    // We return the result of the comparison on the created_timestamp
    	    return strcmp( $data_b->post_date, $data_a->post_date );
        }
    		
    	function order_by_title( $id_a, $id_b ) {
    		// We get the information for each id we need to compare
    		$data_a = $this->data[$id_a];
    		$data_b = $this->data[$id_b];
    		// We return the result of the comparison on the title
    		return strcmp( $data_b['meta']['image_meta']['title'], $data_a['meta']['image_meta']['title'] );
    	}
    
    	function my_mgl_sort( $ids, $data, $layout, $atts ) {
    		// Data contains metadata about the media (use printf on it to understand its structure)
    		$this->data = $data;
    		
    		// The usort function will order the $ids depending on a function.
    		// For fun, we pick a different function for the Tiles and Masonry layouts only.
    		if ( $layout === 'masonry' )
    			usort( $ids, array( $this, "order_by_title" ) );
    		else if ( $layout === 'tiles' )
    			usort( $ids, array( $this, "order_by_upload_date" ) );
    		return $ids;
    	}
    }
    
    new My_Custom_Order_For_Meow_Gallery();

    I even tried reversing the order to check the results, but only some images get moved around.

    usort( $ids, array_reverse( $this, "order_by_upload_date" ) );

    Am I missing something easy, or is something going on with my particular installation? I am using a child theme and this gallery code is the only PHP code added to it.

    I don’t consider myself having a lot of plugins, but does anything stand out to you that could interfere?

    Analytify
    Broken Link Checker
    Classic Editor
    Duplicate Post
    Easy Updates Manager
    Instagram Widget by WPZOOM
    Mailchimp for WordPress
    Media Cleaner
    Meow Gallery Block
    Meow Lightbox
    Post Date Time Change
    Social Pug
    UpdraftPlus – Backup/Restore
    Webcraftic Disable Admin Notices Individually
    Yoast SEO

    Thanks.

    Hi again,
    Well I never got sorting to work but I did end up purchasing a lifetime license to your gallery. I really do love the gallery but sorting should not be such a chore.

    Cheers.

Viewing 15 replies - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.