Add a button above related listing section of each listing

i want to add a button above related listing section of each listing which tke me to the current lsiting category page.

Hi,

You can do this using two solutions:

  1. Add content block before related listings using PHP snippet, you can check this sample: Add custom content to the listing search page sidebar #hivepress #templates · GitHub

  2. Or you can overwrite this template in HivePress > Templates, you can check this doc: How to customize templates - HivePress Help Center

​I hope this is helpful to you.

Hello can i get the current listing category link like that ??

 add_filter('hivepress/v1/templates/listing_view_page',

	function( $template ) {
        $category_ids = $listing->get_categories__id();
		$first_category_id = ! empty( $category_ids ) ? reset( $category_ids ) : 0;

		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'page_sidebar' => [
						'blocks' => [
							'custom_name_here' => [
								'type'    => 'content',
								'content' => '<div class="view-category-btn"> <a href="' . esc_url( get_category_link( $first_category_id ) ) . '" class="button" id="specific-category-button">View More</a></div>',
								'_order'  => 10,
							],
						],
					],
				],
			]
		);
	}
);

When i run the above code its giving me the critical wordpress error

Hi,

Please note that we cannot debug your code, as this is not within the scope of our support, and we can only provide general recommendations. You can try using: $listing=hivepress()->request->get_context(‘listing’) , in your function, before you use the listing to get the category.

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