Advertisement:

Author Topic: code help  (Read 317 times)

Offline gecitli

  • Jr. Member
  • **
  • Posts: 369
    • webmaster forumu
code help
« on: January 27, 2021, 07:44:50 AM »
How do I include hello person avatar in code?

Code: [Select]
$array = ssi_recentPosts(5, null, null, 'array');

echo '
<div class="p-4 space-y-4">
<ul class="sonileti">';
foreach ($array as $widgetposts)
echo '
<li class="block-row">
<div class="contentRow">
<span class="d-block text-dark text-capitalize text-truncate mw-150p">', $widgetposts['link'], '</span>
', $txt['by'], ' ', $widgetposts['poster']['link'], ' (', $widgetposts['board']['link'], ')
</div>
</li>';

echo '
</ul>
</div>
http://www.webtiryaki.com

webmaster forumu

Free & Premium Responsive Themes for SMF.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 60,073
  • Gender: Male
    • Kindred-999 on GitHub
Re: code help
« Reply #1 on: January 27, 2021, 09:57:27 AM »
add this to see the entire array....

echo '<pre>'; print_r($widgetposts); echo '</pre>';
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Offline gecitli

  • Jr. Member
  • **
  • Posts: 369
    • webmaster forumu
Re: code help
« Reply #2 on: January 27, 2021, 11:45:25 AM »
add this to see the entire array....

echo '<pre>'; print_r($widgetposts); echo '</pre>';

I'm sorry I don't understand the logic of getting a print?

Code: [Select]
$array = ssi_recentPosts(5, null, null, 'array');
loadMemberData(array_map(function($post) {
return $post['poster']['id'];
}, $context['latest_posts']));
echo '
<div class="p-4 space-y-4">
<ul class="sonileti">';
foreach ($array as $widgetposts)

loadMemberContext($post['poster']['id']);

if (!empty($post['poster']['id']))
$avatar = $GLOBALS['memberContext'][$post['poster']['id']]['avatar'];
else
$avatar = array('image' => '<img class="avatar" src="'.$GLOBALS['modSettings']['avatar_url'] . '/default.png'.'" alt="avatar">');

echo '
<li class="block-row">
<div class="contentRow">
<div class="poster-avatar">', $avatar['image'], '</div>
<span class="d-block text-dark text-capitalize text-truncate mw-150p">', $widgetposts['link'], '</span>
', $txt['by'], ' ', $widgetposts['poster']['link'], ' (', $widgetposts['board']['link'], ')
</div>
</li>';

echo '
</ul>
</div>

It doesn't have to be like this

I can set these codes as how they work.
http://www.webtiryaki.com

webmaster forumu

Free & Premium Responsive Themes for SMF.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 60,073
  • Gender: Male
    • Kindred-999 on GitHub
Re: code help
« Reply #3 on: January 27, 2021, 11:53:37 AM »
you asked "how do I get the avatar to display"?

I provided a line of code that, when triggers, shows you the entire array including every variable that you can use within that array...

it's a debugging thing that you can use to find out the proper variable name(s).

however, $avatar['image'] is not valid.... $avatar is not an array - it's a single variable, so calling the sub-variable as if it was an array won't work.

also $post['poster']['id']??
just before that, you said: foreach ($array as $widgetposts)

so you should be working with the $widgetposts[...] array variable

plus, I don't think that you need to loadmembercontext....
like I said --   do the print_r to find out what variables are included in the array already
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Offline gecitli

  • Jr. Member
  • **
  • Posts: 369
    • webmaster forumu
Re: code help
« Reply #4 on: January 27, 2021, 11:58:16 AM »
got it Kindred thank you.
http://www.webtiryaki.com

webmaster forumu

Free & Premium Responsive Themes for SMF.