Customising listing page with attributes in a row

Hi.
I’m trying to customise the listing page. I will create a new ‘listing’ template and rebuild the ‘listing’ page, but for now I’m just trying to see how it looks. I need for some listing attributes to appear alongside each other, so next to each other and not all just in a column going down. One section will be the phone number, and next to it I want the user to be able to select if contactable by Whatsapp or not and another attribute will be Telegram. So that would be three different attributes appearing in a row going across. There are other sections I will create that need many attributes next to each other, so the standard template and setup doesn’t allow for that. The ‘Area’ Page (Secondary) display doesn’t give me enough cusomisation, they need to be next to each other in a row, and I need many sections.

I have the code below and will build a table where the paragraph tag currently is, but I need to be able to call more than one listing attribute using ‘get’. With this code I only seem to be able to call the get_phone attribute. When I try more it doesn’t display. I’ve removed the failed code. Does anyone know how to call more than one listing attribute in that code? Also, maybe when I create a ‘listing’ template I could use shortcodes and put them in a table. Any help is much appreciated.

add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$attribute_one = $listing->get_phone();
			
		if(!$attribute_one){
			return $blocks;
		}
			
		return hivepress()->template->merge_blocks(
					$blocks,
					[
						'page_sidebar' => [
								'blocks' => [
									'custom_text' => [
										'type' => 'content',
										'content' => '<p><strong>'.$attribute_one.' and '.$attibute_two.'</strong></p>',
										'_order' => 20,
									],
								],
							],
				]
				);
		},
	
	1000,
	2
);
2 Likes

Hi,

Sorry, there’s no simple code snippet for this, it would require a custom implementation. If customizations beyond the available features are required for your site, please consider hiring someone for custom work https://fvrr.co/32e7LvY

I discovered that the below code does display more than one attribute, but only when the field type is ‘text’ and the user submitting the listing enters text. When the field type is ‘select’ nothing displays. Does anyone know how to change the code below to display values when the field is select and also even a checkbox ? If the city attribute is text and the user types the city name, then it displays. But I would prefer to make the city and country attributes as ‘select’, and set the city and country so that the user doesn’t spell them incorrectly. They might also be multiple select, so can select two cities. Is it also possible to display their labels if needed as well? So I might like it display in a row with something like City: Madrid in Spain. The code below only displays Madrid in Spain and only when the fields are text type. Please can someone help.

add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$attribute_one = $listing->get_city();
		$attribute_two = $listing->get_country();
			
		if(!$attribute_one && !$attribute_two){
			return $blocks;
		}
			
		return hivepress()->template->merge_blocks(
					$blocks,
					[
						'page_sidebar' => [
								'blocks' => [
									'custom_text' => [
										'type' => 'content',
										'content' => '<p><strong>'.$attribute_one.' in '.$attribute_two.'</strong></p>',
										'_order' => 20,
									],
								],
							],
				]
				);
		},
	
	1000,
	2
);

If you mean setting more attributes in one row in the listing page secondary attribute area, then please try this PHP code snippet. For example, this code snippet set 4 attributes per row, and you can change this number, but please note that it can require further customization. If you are not familiar with the code customization, then please consider hiring someone for custom work https://fvrr.co/32e7LvY

add_filter(
	'hivepress/v1/templates/listing_view_page',
	function($template){
		return hivepress()->template->merge_blocks(
			$template,
			[
				'listing_attributes_secondary' => [
					'columns' => 4,
				],
			],
		);
	},
	1000
);
1 Like

Thanks for the reply yevhen, that’s kind of you. Your code might be useful, so thanks. But if you see my second post in this thread, the code I’ve shown works, but only when the user types into a ‘text’ field on the listing submission page. If the field type is a ‘select’ option, my code fails. I would like to have the flexibility to show the label of one attribute and the value of two attributes or maybe even three and all right next to each other. An example would be for the attributes ‘City’ and ‘Country’, I would like to output the data; City: Madrid in Spain. I would like those to appear right next to each other with the word ‘in’. With your method that would output
City: Madrid Country: Spain. Plus with your method there would be a big gap, and they would also appear in the secondary area. With my code it outputs ‘Madrid in Spain’ and in the side column below primary.

The two problems I have in my code is that it doesn’t output the label for ‘City’. But the main problem is that the code in my second post above only outputs the attribute values if the user types in text to a ‘text’ field. I want my City and Country both to be ‘select’ options on the listing submission form. So the person submitting a listing will ‘select’ the city Madrid rather than having to type it in.

I hope I have explained in enough details. Any help is much appreciated.

Thank you for the clarification. In this case, please try to get the value of the attribute like

$listing->display_city();

instead of

$listing->get_city();

It should solve an issue with the selectable attributes

1 Like

Thank you so much yevhen, I really appreciate it. I’ve been pulling my hair out over this, so I’m very happy. I tested it and it works. perfectly. If there is a way to also get and display the label, so the word ‘City’, then that would also be great to know, mainly for a different section I want to add. Knowing how to get the label just gives even more flexibility. But, I’m still happy with the help you have given me. I’m very grateful to you.

It is possible to get the name of the attribute in this way.

$fields = $listing->_get_fields();
		
$field = hivepress()->helper->get_array_value($fields, 'city');
		
$attribute_label = $field->get_label();
1 Like

Thanks so much for your help, that’s perfect.

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