Add view more button in the listing block

I am trying to add a view more button on the listing block footer so user can click and get to the listing details page. I have this snippet and I am trying to figure out the dynamic link for listing details.

add_filter('hivepress/v1/templates/listing_view_block', function($template){
    return hivepress()->helper->merge_trees($template, [
        'blocks' => [
            'listing_footer' => [
                'blocks' => [
                    'custom_button' => [
                        'type' => 'content',
                        'content' => '<div class="footer_spacer"></div><div><a href="listing_details_link_here" class="button">More >></a></div>',
                        '_order'=>40,
                    ]
                ]
            ]
        ]
    
    ]);
});

Can you help me with figuring out what should go in the listing_details_link_here so that the link opens the view listing details for the listing? Thanks.

Hi,

Please try to use this hook: hivepress/v1/templates/listing_view_block/blocks Filter: hivepress/v1/templates/{template_name}/blocks | HivePress Hook Reference. This hook has two parameters, you can get the context from the template: $template->get_context(‘listing’), and then get the listing URL: get_permalink($listing->get_id())

​I hope this is helpful to you.

I updated my code using your suggestion and it is still not working, what I am missing? Thank you!

add_filter(
    'hivepress/v1/templates/listing_view_page/blocks',
    function( $blocks, $template ) {

        $listing = $template->get_context('listing');
        
        if (!$listing) {
            return $blocks;
        }
        $url = get_permalink($listing->get_id());

        return hivepress()->helper->merge_trees( $template, [
			'blocks' => [
				'listing_footer' => [
					'blocks' => [
						'custom_button' => [
							'type'    => 'content',
							'content' => '<div class="footer_spacer"></div><div><a href="' . $url . '" class="button">More</a></div>',
							'_order'  => 40,
						]
					]
				]
			]
        ]);

    },
    1000,
    2 
);

Hi,

We still recommend that you try using this hook: hivepress/v1/templates/listing_view_block/blocks, because the listing_footer of the block is not in the listing_view_page.

Oh sorry, that was a typo, let me fix that and get back to you. Thanks!

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