Home Support General HivePress How to add a custom attribute in the listing block?

How to add a custom attribute in the listing block?

  • Author
    Posts
  • MeetHub

    Hi, morning! I’m trying to add a custom Attributes between vendor name and categories name. Is that possible?

    ihor developer

    Please try selecting the display areas for this attribute, there are 2 display areas for each listing view (block or page) by default.

    MeetHub

    Hi, @ihor!

    Actually i have an attibute from vendors, and i want to display this attribute in listing block.

    From here: https://prnt.sc/1s6is8w (Vendor Backend)
    From here: https://prnt.sc/1s6ivjv (Vendor Frontend)

    To Here: https://prnt.sc/1s6j2az (Listing Frontend)

    MeetHub

    I know where to put the information, already tested.

    I need to know how to call a foreign attribute in the template.

    add_filter('hivepress/v1/templates/listing_view_block', function ($template) {
      return hivepress()->helper->merge_trees($template, [
        'blocks' => [
          'listing_content' => [
            'blocks' => [
              'listing_details_primary' => [
                'blocks' => [
                  'custom_cargo_atual' => [
                    'type' => 'taxonomy',
                    'taxonomy' => 'Cargo Atual'
                  ]
                ]
              ]
            ]
          ]
        ]
      ]);
    });
    MeetHub

    i’m thinking if using a snippet to retrieve this attribute and using type => part and path => ‘…’ pattern i can render this.

    ihor developer

    Sure, you can insert a custom block of a “part” type and set the template path for it, then in the template file you can use this code to retrieve the attribute value:

    $vendor->get_attributenamehere();

    You can also override some existing template part without adding a new one, for example /listing/view/block/listing-vendor.php and add any custom content at the end https://www.youtube.com/watch?v=LkojYp-8uwY&ab_channel=HivePress

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

You must be logged in to reply to this topic.