How to target listing price and attributes

Hi
I changed the default code in this file:

https://my.website/wp-admin/plugin-editor.php?file=hivepress-geolocation%2Fincludes%2Ftemplates%2Fclass-listing-map-block.php&plugin=hivepress-geolocation%2Fhivepress-geolocation.php

with the following code:

<?php
/**
 * Listing map block template with location and image.
 *
 * @package HivePress\Templates
 */

namespace HivePress\Templates;

use HivePress\Helpers as hp;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

/**
 * Listing map block template class with location and image.
 *
 * @class Listing_Map_Block
 */
class Listing_Map_Block extends Template {

    /**
     * Class constructor.
     *
     * @param array $args Template arguments.
     */
    public function __construct( $args = [] ) {
        $args = hp\merge_trees(
            [
                'blocks' => [
                    'listing_container' => [
                        'type'       => 'container',
                        '_order'     => 10,

                        'attributes' => [
                            'class' => [ 'hp-listing', 'hp-listing--map-block', 'custom-popup-width' ], // Added custom class for width
                        ],

                        'blocks'     => [
                            'listing_title' => [
                                'type'       => 'container',
                                'tag'        => 'h5',
                                '_order'     => 10,

                                'attributes' => [
                                    'class' => [ 'hp-listing__title' ],
                                ],

                                'blocks'     => [
                                    'listing_title_text' => [
                                        'type'   => 'part',
                                        'path'   => 'listing/view/block/listing-title',
                                        '_order' => 10,
                                    ],

                                    'listing_verified_badge' => [
                                        'type'   => 'part',
                                        'path'   => 'listing/view/listing-verified-badge',
                                        '_order' => 10,
                                    ],
                                ],
                            ],

                            'listing_location' => [
                                'type'       => 'container',
                                'tag'        => 'h5',
                                '_order'     => 20,

                                'attributes' => [
                                    'class' => [ 'hp-listing__location' ],
                                ],

                                'blocks'     => [
                                    'listing_location_text' => [
                                        'type'   => 'part',
                                        'path'   => 'listing/view/listing-location',
                                        '_order' => 20,
                                    ],
                                ],
                            ],

                            'listing_image' => [
                                'type'       => 'container',
                                'tag'        => 'div',
                                '_order'     => 25, // Adjust the order as needed

                                'attributes' => [
                                    'class' => [ 'hp-listing__image' ],
                                ],

                                'blocks'     => [
                                    'listing_image_content' => [
                                        'type'   => 'part',
                                        'path'   => 'listing/view/block/listing-image', // Ensure this path outputs the image
                                        '_order' => 25,
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
            $args
        );

        parent::__construct( $args );
    }
}

So now the popup shows the listing title, address, and images, the question is how do i add to this the listing price, and some attributes

Thank you so much.

Hi,

Thank you for your solution, it will be useful for our community. But please note that we recommend adding custom code using this documentation How to add custom code snippets - HivePress Help Center, because if you change the code directly in the theme folders, it will automatically restore after an update from our side.

Hi and thanks for your reply, i usually use snippets, but here i was not sure how to target the right code with the snippet
Can you give me guidance how to add the price and attributes, i could not figure out the right path to these data
By the way i also have css for this to make the popup look nicer and better if anyone needs it please reply.

Please consider using hivepress/v1/templates/listing_map_block hook to add custom code snippets, this way you can insert custom blocks/content to the template without editing it directly, otherwise any direct changes will be reset on update. You can find some sample code snippets here Search · user:hivepress templates · GitHub

You can insert custom blocks using code snippets, and if the listing object is available there, you can show any details this way:

echo $listing->display_price();

Hope this helps

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