Adding listing name/hyperlink in the Message Thread list

Hello,
In the Message Thread view, where you can see all the messages from all senders for your listings, the default view displays only the sender name and the date, which means you can see the actual listing they messaged about (its title and URL) only if you open up the message.

I’m trying to find a way to display the listing title which is the subject of the message (preferably with a hyperlink to the listing) in the thread view, between the sender name and the date, but I couldn’t do it so far.

Here is the code snippet I came up with, which I replaced in the “message-listing.php” file from the “thread” file under templates->message :

<?php
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

error_log('Thread View: Checking for listing ID in message thread template.'); // Debug log

if ( $message->get_listing__id() ) : 
    error_log('Listing ID found in thread: ' . $message->get_listing__id()); // Log listing ID

    ?>
    <td class="hp-message__listing">
        <a href="<?php echo esc_url( hivepress()->router->get_url( 'listing_view_page', [ 'listing_id' => $message->get_listing__id() ] ) ); ?>" target="_blank" class="hp-link">
            <i class="hp-icon fas fa-external-link-alt"></i>
            <span><?php echo esc_html( $message->get_listing__title() ); ?></span>
        </a>
    </td>
    <?php
else :
    error_log('No listing ID found in thread view.'); // Log if no listing ID
    ?>
    <td class="hp-message__listing">No listing available</td>
    <?php
endif;

But for some reason is not able to get the listing title/URL, always displaying “No listing available” and the logs say “no listing ID found”.

Did anyone manage to do this?

Thanks!

Hi,

Sorry for the delay. The related listing link should actually appear for each thread, but only if the latest message in the thread has been sent via the Reply to Listing button, not directly hivepress-messages/includes/templates/class-message-thread-block.php at master · hivepress/hivepress-messages · GitHub If you want to display it even if the last message is sent directly, I recommend overriding this template part via a child theme hivepress-messages/templates/message/thread/message-listing.php at master · hivepress/hivepress-messages · GitHub and add some logic to it to find the most recent message related to a listing, finding the listing this way and showing its link. I also recommend caching the query to avoid an extra SQL query for messages on every displayed thread.

Hope this helps

Hello ihor,

No worries about the delay, your efforts are greatly appreciated in the community!
I will try to implement what you suggested and see if I can make it work. However, in the meantime I’ve done some testing and I discovered that the functionality for the Messages is a bit unusual - threads seem to be organized per user, not per listing (i.e if an user replies to 5 different listings from the same vendor, they will all appear under the same thread). Right now I am working to see if I can change this, to have one thread for each listing, even if the messages are coming from the same user.

No worries, I’m glad I could help.

Yes, each thread is unique per 2 users, like with a message chat. A message can be “attached” to a listing if sent via the listing page, but in the thread view, this link is visible only if the last message is attached to a listing, showing the link for the most recent attached listing (even if it’s not the most recent message) may improve the UX.

1 Like

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