Join our new community forum for support & discussion

Join Now

Home Support Themes TaskHive Move listing category description

Move listing category description

  • Author
    Posts
  • Eve

    Hello,

    Can You give me the exact snippet to duplicate listing category descriptions after listings (https://ibb.co/hVFXZPs).

    I’ve tried several ones but it doesn’t work

    Can you help me please ?

    Examples :

    add_action(
    	'template_redirect',
    	function() {
    		if ( is_tax( 'hp_listing_category' ) ) {
    			add_filter(
    				'hivepress/v1/templates/listings_view_page',
    				function( $template ) {
    					$listing_categoryID = get_the_id();
    					return hivepress()->helper->merge_trees(
    						$template,
    						[
    							'blocks' => [
    								'page_footer' => [
    									'blocks' => [
    										'custom_content' => [
    											'type'    => 'content',
    											'content' => get_post($listing_categoryID)->post_content
    										],
    									],
    								],
    							],
    						]
    					);
    				}
    			);
    		}
    	},
    	1
    );

    OR

    add_action(
    	'template_redirect',
    	function() {
    		if ( is_tax( 'hp_listing_category' ) ) {
    			add_filter(
    				'hivepress/v1/templates/listings_view_page',
    				function( $template ) {
    					$listing_categoryID = get_the_id();
    					return hivepress()->helper->merge_trees(
    						$template,
    						[
    							'blocks' => [
    								'page_footer' => [
    									'blocks' => [
    										'custom_content' => [
    											'type'    => 'content',
    											'content' => get_listing_category($listing_categoryID)->listing_category_description
    										],
    									],
    								],
    							],
    						]
    					);
    				}
    			);
    		}
    	},
    	1
    );
    yevhen developer

    Please try this PHP snippet

    add_filter('hivepress/v1/templates/listings_view_page/blocks', function($blocks, $template){
    		$listing_category = $template->get_context('listing_category');
    		if($listing_category){
    			$blocks = hivepress()->helper->merge_trees(
    					[ 'blocks' => $blocks ],
    					[
    						'blocks' => [
    							'listings_container' => [
    								'blocks' => [
    									'custom_category_description' => [
    										'type' => 'content',
    										'content' => category_description($listing_category->get_id()),
    										'_order' => 1000,
    									],
    								]
    							]		
    						]
    				]
    				)['blocks'];
    		}
    
    	return $blocks;
    }, 1000, 2);
    Eve

    Thank you so much !

    Eve

    Hello,

    Can you please give me the exact same PHP snippet for listing tags ?
    Regards

    yevhen developer

    Please try this PHP snippet but please note that it may require further customisation

    add_filter('hivepress/v1/templates/listings_view_page/blocks', function($blocks, $template){
    		if(hivepress()->get_version( 'tags' )){
    			$tags = get_terms( [
    			'taxonomy'   => 'hp_listing_tags',
    			'hide_empty' => true,
    			] );
    			
    			$tag_view = '';
    			
    			foreach($tags as $tag){
    				$tag_view .= '<a href="' . esc_url( get_term_link( $tag ) ) . '">' . esc_html( $tag->name ) . '</a> ';
    			}
    			
    			$blocks = hivepress()->helper->merge_trees(
    					[ 'blocks' => $blocks ],
    					[
    						'blocks' => [
    							'listings_container' => [
    								'blocks' => [
    									'custom_category_description' => [
    										'type' => 'content',
    										'content' => $tag_view,
    										'_order' => 1000,
    									],
    								]
    							]		
    						]
    				]
    				)['blocks'];
    		}
    
    	return $blocks;
    }, 1000, 2);
    Eve

    Thank you @yevhen.
    But you give me a snippet to display terms.
    I need to display description.

    Maybe a unique one to display both ? Terms and description ? 😉
    (Good idea to display other terms for SEO)

    ihor developer

    Please update HivePress and try adding descriptions to any taxonomy other than category, it should work without the code snippets now.

    Eve

    Thank you @ihor (nice update !) but the tag descriptions are displayed above the listings.

    In SEO, we need to write long content. But, for UX/UI issues, we can’t show long content before the results list.

    Can you please give me the snippet that allows the description of the tags to be displayed below the listings.

    yevhen developer

    Please try this PHP snippet

    add_filter('hivepress/v1/templates/listings_view_page/blocks', function($blocks, $template){
    
    	return hivepress()->helper->merge_trees(
    					[ 'blocks' => $blocks ],
    					[
    						'blocks' => [
    							'page_content' => [
    								'blocks' => [
    									'page_description' => [
    										'_order' => 1000,
    									],	
    								],
    							],
    						],
    				]
    				)['blocks'];;
    }, 1000, 2);
    Eve

    Thank You yevhen !

Viewing 10 posts - 1 through 10 (of 10 total)

New Reply

This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.