Hello,
I have been reviewed some forum entries like:
I have a vendor attribute called “Company Name.” I would like to add this attribute to the listings page for each listing under the Title and above the address. Or I would like to have it added in the Title. (i.e. XYZ Bank - Open Free Account) where the user types in “Open Free Account” but the “XYZ Bank” (Company Name) is defaulted. I can see that %listing% and %vendor% tokens are an option in the setting but I don’t know how they work. Please advise. Thank you.
[image]
But it’s not clear for me the possibility to add or not the vender in the listings block. I am trying to add some code snippet with the variable “$listing->get_user__id()”, but I can’t.
Is it possible to do it with a code snippet similar to this one?
add_filter('hivepress/v1/templates/listing_view_block', function( $template ) {
return hivepress()->helper->merge_trees($template, [
'blocks' => [
'listing_content' => [
'blocks' => [
'custom_text' => [
'type' => 'content',
'content' => "$listing->get_user__id()",
'order' => 15,
]
]
],
],
]
);
}
);
Thanks and regards,
andrii
March 14, 2024, 1:41pm
3
Hi,
Please provide more details. Do you need to add a vendor name to the listing block? Also, what kind of theme do you use?
Hi,
Yes, I would like to add a vendor name to the listing block. I am trying to get the vendor from the listing and doing the same procedure that is done in this tutorial video which tells the addition of a new button:
# Customizing Templates I HivePress Developer Docs
Theme is HivePress,
Thanks and regards!
Hi!
I finally solved overwritting code in listing-image.php with the following sentence:
<?php echo "Vendor: "; $user = $listing->get_user(); echo $user->get_display_name(); ?>
I don’t know if it is possible doing this with code snippet which is more elegant.
Thanks and best regards,
andrii
March 15, 2024, 12:36pm
8
Hi,
To extract an object from the listing context, you need to use the same hook, but add /blocks
at the end, then the second argument of the function is a template, and you can $template->get_context('listing')
, and then $listing->get_vendor__name()
.
Hi!
I finally solved like this:
add_filter(
'hivepress/v1/templates/listing_view_block/blocks',
function( $blocks, $template ) {
$listing = $template->get_context('listing');
if($listing && $listing->get_vendor__name()){
$blocks = hivepress()->helper->merge_trees(
[ 'blocks' => $blocks ],
[
'blocks' => [
'listing_details_primary' => [
'blocks' => [
'custom_listing_block_description' => [
'type' => 'content',
'content' => '<p style="font-size: 10px;">'.esc_html($listing->get_vendor__name()).'</p>',
'_order' => 6,
],
],
],
],
]
)['blocks'];
}
return $blocks;
},
1000,
2
);
Thanks and best regards,
I have been wanting to do the same! thanks @paperboy
I have upgraded the idea to make the links lead to the vendor profile.
<?php
add_filter(
'hivepress/v1/templates/listing_view_block/blocks',
function( $blocks, $template ) {
$listing = $template->get_context('listing');
if ($listing && $listing->get_vendor()) {
$vendor = $listing->get_vendor();
$vendor_slug = $vendor->get_slug();
// Construct the vendor profile URL using the slug
$vendor_url = 'https://yousite.com/vendor/' . $vendor_slug . '/';
$blocks = hivepress()->helper->merge_trees(
[ 'blocks' => $blocks ],
[
'blocks' => [
'listing_details_primary' => [
'blocks' => [
'custom_listing_block_description' => [
'type' => 'content',
'content' => '<p style="font-size: 14px;"><a href="' . esc_url($vendor_url) . '">' . esc_html($vendor->get_name()) . '</a></p>',
'_order' => 6,
],
],
],
],
]
)['blocks'];
}
return $blocks;
},
1000,
2
);
Thinking about adding the seller’s photo to make the listings more personal
For anyone visiting this post, you can use this code reference to add customizations anywhere
andrii:
To extract an object from the listing context, you need to use the same hook, but add /blocks
at the end, then the second argument of the function is a template, and you can $template->get_context('listing')
, and then $listing->get_vendor__name()
.
https://hivepress.github.io/code-reference/files/hivepress-includes-models-class-vendor.html
It looks great! @thefourcraft
I was able to change the listing image to the category image like this:
Hi!
I finally success to do it. Looking at the code I found a method to obtain the array of categories and I take the first one.
So finally I have change the original code line:
<img src="<?php echo esc_url( hivepress()->get_url() . '/assets/images/placeholders/image-landscape.svg' ); ?>" alt="<?php echo esc_attr( $listing->get_title() ); ?>" loading="lazy">
With this:
<?php foreach ( $listing->get_categories() as $category ) : ?>
<img src="<?php echo esc_url( $category->get_image__url( 'h…
I think you could modify the child template in the same way, at the beginning or the end of the listing.
Regards!
system
Closed
April 22, 2024, 12:47pm
12
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.