Is it possible to force the listings take image from its upper category?


I have succesfully disabled in the upload listing form the upload image field following this Code Snippet from the resources:

	function ($form){
		return $form;

but I would like every listing can show the image from it’s category, is it possible?

Thanks and regards,


Yes, this is possible, but you need to overwrite the Listing Image template part using the child theme and add logic there, extracting the category image and showing the following instead of the listing image, you can check this doc: How to override template parts - HivePress Help Center

​I hope this is helpful to you.

Thanks, I will check it!

Best regards,

Thanks for indications,

I have located the listing-image.php file and create and test a theme-child succesfully

I still have some doubts. How could I extract category from image?

I don’t find any doc/class or similar with all methods such us:


With the category I can overwrite the default sentence with the image of the category:

<img src="<?php echo esc_url( $listing_category->get_image__url( 'hp_landscape_small' ) ); ?>" alt="<?php echo esc_attr( $listing_category->get_name() ); ?>" loading="lazy" />

Thanks and best regards,


I finally success to do it. Looking at the code I found a method to obtain the array of categories and I take the first one.

So finally I have change the original code line:

<img src="<?php echo esc_url( hivepress()->get_url() . '/assets/images/placeholders/image-landscape.svg' ); ?>" alt="<?php echo esc_attr( $listing->get_title() ); ?>" loading="lazy">

With this:

<?php foreach ( $listing->get_categories() as $category ) : ?>
	<img src="<?php echo esc_url( $category->get_image__url( 'hp_landscape_small' ) ); ?>" alt="<?php echo esc_attr( $category->get_name() ); ?>" loading="lazy" />
<?php break; endforeach; ?>

I have checked references and I still not find any doc/class/references related with the detail information about different methods, is there any concrete different to check?

Best regards!


Your snippet looks good, but I also recommend that you go through our documentation in more detail, especially on methods, please check this doc: Models | Developer Docs

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.