Separate line for a particular attribute

For an attribute - I have on the homepage and listing page
Where user can choose maximum of values
Each value is separated by ,
But they are on the same line after each other
Is there a way to make the 3 values on separate line?

Hi @mheefu,

If you use <br> in the display section, this will add a new line, use multiple <br> to create more space. However, If the string of information is all spat out at once you might need a different approach.

I hope this helps!

Cheers,
Chris :victory_hand:

In attribute format (optional) I set %value%
but it didn’t work - should I be during that at some other place? Thank you

Hi @mheefu,

Where you see %value% is where I meant to add the <br>'s. However, I don’t think this will address your issue, so I had a go at solving it another way.

This is untested code, so use with caution.

Using the Code Snippets plugin is probably the easiest way for you to do this. You can install it from the WordPress directory, if you’re not already familiar with it.

Once it’s installed and activated, add the following (see notes) as a new snippet. Save and activate it.

add_filter( 'hivepress/v1/templates/listing_view_block/attributes', function( $output, $attributes, $listing ) {
    $custom_output = '';
    foreach ( $attributes as $attribute ) {
        $slug = $attribute->get_slug();
        $value = $listing->{'get_' . $slug}();
        if ( $slug === 'thispart' && is_array( $value ) ) {
            $custom_output .= '<div>' . implode( '<br>', $value ) . '</div>';
        } else {
            $custom_output .= $attribute->display();
        }
    }
    return $custom_output;
}, 10, 3 );

Note: change thispart in the code above to match the slug name of the attribute you’d like to display with the selections as a list.

I hope this works/helps!

Cheers,
Chris :victory_hand:

Thank you Chris - I tried but it did not work - not sure of the reason though
Maybe will have to live with it for now :slight_smile:

Hi,

Unfortunately, this feature is not available by default and would require a custom implementation. If you need to make custom changes to your site, you can explore our collection of code snippets here: Search · user:hivepress · GitHub, along with other developer resources. Alternatively, you may consider hiring a developer for custom work: Customize your website | HivePress