Codoforum related discussions
When sharing a topic, the topic image is not good

Hello!
I want to ask for help!
When I try to share a topic, the site logo appears instead of the topic image. Which file and where should I modify to display the image attached to the topic when sharing the topic?
Thank you very much!
6140974aab4e7


Hello! I want to ask for help! When I try to share a topic, the site logo appears instead of the topic image. Which file and where should I modify to display the image attached to the topic when sharing the topic? Thank you very much! ![6140974aab4e7](serve/attachment&path=6140974aab4e7)
edited Sep 14 '21 at 2:20 pm

I've solved it!
@nguoianphu Based on your description!
By using code
// Get image link for Facebook sharing

    // search the first image link from the first post of the topic
$image = $posts[0]['message'];

// initialize the image link with the default thumbnail image
$img_src = 'https://domain.com/logo.png';

// pattern to get the src value in the img tag
$pattern = '/src="([^"]*)"/';

// If found image link, use it. Else, use the default
preg_match($pattern, $image, $matches);
if (!empty($matches[1])){
$img_src = $matches[1];
}
unset($matches);

// Set the Open Graph image property
\CODOF\Store::set('og:image', $img_src);

the sys/controller/forum.php
Thank you for the infot


I've solved it! @nguoianphu Based on your description! By using code // Get image link for Facebook sharing // search the first image link from the first post of the topic $image = $posts[0]['message']; // initialize the image link with the default thumbnail image $img_src = 'https://domain.com/logo.png'; // pattern to get the src value in the img tag $pattern = '/src="([^"]*)"/'; // If found image link, use it. Else, use the default preg_match($pattern, $image, $matches); if (!empty($matches[1])){ $img_src = $matches[1]; } unset($matches); // Set the Open Graph image property \CODOF\Store::set('og:image', $img_src); the sys/controller/forum.php Thank you for the infot
47
1
1
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft