Listify

Listify: How to display default images based on category

David Nash wordpress 4 Comments

You use Listify, the popular directory listing WordPress theme, but want to set default images on a category basis. Here’s how!

To customise Listify, it’s best to use a child theme. Listify supplies a skeleton for you to do this. In the child theme’s functions.php, add this:

How this relates to Listify

Listify has its own categories for listings. Don’t confuse them with WordPress post categories. Listify calls them job_listings because it’s based on a Jobify. Some of this terminology has carried across.

When you create a listing category in Listify, you’ll get a category slug. In the child theme’s folder, create an “images” directory. Then all you need to do is upload images with cat-slugname.jpg for it to work.

For example if my category was “Assassins”, the slug would be “assassins”. Upload wp-content/themes/listify-child/cat-assassins.jpg. Now that image will appear as the background for any listings that didn’t upload an image.

I like this solution. As long as the client has FTP access, they can update the image when they like. If they create a new category, they can upload an image with the same filename format and it’ll just work, without any extra development costs.

Comments 4

  1. Hi David,
    Thank you very much for that code 😉
    I would just report you that there is an issue that i am not able to fix. All worked well before i install the plugin FacetWP. Actually the listings “bubble” map display randomly any image from any other listing gallery. Precisely it concerns any listing which doesn’t still have featured or gallery image. I have tried to save permalinks, seo permalinks, empty translated cache but no way to fix that issue.
    For now after some tests, if you go on my website homepage http://loctim.com/fr , you have 2 ways to display listings :
    1. by the top menu “Rechercher”
    2. by the homepage FacetWP search button (i have hide it): http://loctim.com/fr/ads/
    This issue is produced only in the second case not in first. And also when filter are empty, because if i set one filter, all works in each cases.
    Regards and thanks again
    Charly

  2. Hey thank you so much. I used your code to display map markers with custom images for every slug:
    //add custom listify listing data
    function custom_listify_listing_data( $data ) {
    //code to display the category image thumbnail on map markers
    //get the categories for the listing
    $categories = wp_get_post_terms(get_post()->ID, 'job_listing_category');

    //if it has a category
    if( !empty($categories) ) {
    //look at each category it has
    foreach( $categories as $c ) {
    //check file exists
    $data['thumb'] = '/wp-content/uploads/assets/categories/'.$c->slug.'.jpg';
    break;
    }
    }
    else{
    $data['thumb']= '/wp-content/uploads/assets/categories/image1.jpg';
    }
    return $data;
    }
    add_filter( 'listify_listing_data', 'custom_listify_listing_data' );

  3. I’m yet to purchase listify (but will soon).

    I’m excited to put this code in. It’s always be the bane of my life in other directory software.

    Thank you.

  4. I think it would be more useful to be able to pull the “Featured Image” that you set for each category. I’d love to hear your thoughts on how to tweak the code to do that.

Leave a Reply

Your email address will not be published. Required fields are marked *