Sunday, April 2, 2017

Ajax Load More Shortcode Builder - "Between" Operator

This is just a quick tip for those looking for the same information I just was - if you are looking to use the "Between" operator in conjunction with the "Custom Fields (Meta_Query" filtering part of the Ajax Load More Wordpress plugin, still use the "meta_value" parameter. However, you don't pass in an array (it is expecting a string). Pass it your two values, separated by a comma.

For example, if you have a custom field with the key "price", and you want the load more button to pull in more posts that have the "price" set to between $10 and $20, your shortcode should look something like this:

[ajax_load_more post_type="post" meta_key="product_price" meta_value="10,20" meta_compare="BETWEEN" meta_type="NUMERIC"]
If you want to fill in the range with PHP, simply use the dot concatenation to join the shortcode string with a variable. For example:

<?php echo do_shortcode('[ajax_load_more post_type="post" meta_key="product_price" meta_value="'.$price_low.','.$price_high.'" meta_compare="BETWEEN" meta_type="NUMERIC"]'); ?>
Happy coding!

Sunday, February 12, 2017

Enabling Infinite Scrolling / Ajax Loading on Wordpress Baskerville Theme (Anders Norén)

Baskerville Infinite Scrolling With Plugin

I recently built a website using Anders Norén's free Wordpress theme, Baskerville. This is probably one of the best free themes out there, and definitely the best free theme for sites that are trying to emulate the pinterest / masonry grid style of sites, where individual products are laid out in a re-sizable grid layout.

My only complaint with this theme is that it is just begging to be used with an Ajax infinite scrolling feature, but it does not support it out of the box. I have seen multiple forum posts asking for the author to add it, but it looks like no progress has been made (and I don't blame Anders - he is a very busy and amazingly talented author who deserves to spend his time on more pressing projects).

I didn't want to give up on this theme, but infinite scrolling became a requirement for my new site, so I set out to somehow add the feature to this theme. In the end, it actually didn't take that long to figure out and was not nearly as complicated as I thought.

Initially I was going to take a backend approach and try to rewrite a bunch of PHP, but I quickly realized it would be far easier to use a pre-built plugin to provide the backend support for AJAX loading, and write some Javascript myself to get it working with the theme.

How I added infinite scrolling to the Baskerville Wordpress Theme:

Step 1: Install the "Ajax Load More - Infinite Scroll" Plugin

Sunday, January 22, 2017

Batch Set Image Metadata (Title, Description) To/From Filename

This is a guide on how to bulk change multiple images and set automatically set their metadata "title" and "description" fields to match the filename. For example, if you have a JPG file that has the filename "Family Vacation Group Picture.jpg", after this batch procedure, the image metadata field "title" would contain "Family Vacation Group Picture".

I'm posting this because I was having trouble finding guides on how to do this when Googling them myself. After an hour of searching, there was only one tool that I could find that could read from the filename and put it in the metadata - ExifTool. Every other program out there seems to allow reading from the metadata and using it to rename the file (setting the filename), but that is the opposite of what I was looking for!

Here is how to automatically fill image metadata from filenames. The command used here will set both Description and Title metadata based on filename, without the extension:

I wanted a GUI to do this, so I could visually select files and check metadata. The way to do this on Windows is with ExifTool + ExifToolGUI

  1. Download ExifTool GUI and ExifTool exe and follow directions to place files in same directory
  2. Run ExifTool GUI and navigate inside the program to the files you want to set the metadata for
  3. Click the "ExifTool Direct" button - this allows you input commands for ExifTool that get executed on the files in the selected directory
  4. Copy and paste the following command. You can then either press enter to execute, or, as I did, also save it as a preset so that you can easily execute it again in the future.
    • *.jpg *.jpeg "-Description<${filename;s/\..*?$//}" "-Title<${filename;s/\..*?$//}"

    ExifToolGui - Command to Set Metadata Based on Filename

If you are comfortable with ExifTool without a GUI:

  • I haven't tried this, but the command should be the same as above, but should call exiftool first, like this:
    exiftool *.jpg *.jpeg "-Description<${filename;s/\..*?$//}" "-Title<${filename;s/\..*?$//}"