Uutiset:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu
Advertisement:

Show "You" text for posts by current user?

Aloittaja samborabora, kesäkuu 22, 2014, 11:31:34 AP

« edellinen - seuraava »

samborabora

I'd like to be able to have the text "You" to show on all posts that were made by the currently logged in user. Is there an existing string that can be used, and if not, what would be the proper code to use for this?

Antechinus


samborabora

In the message template, where posts are displayed. I also want to be able to change the color of catbar/cat_bg (where the bar at the top of each post is) to a different color if the post is made by the current user, can this be tied together into the same thing, so the "You" text and the change of styling only occurs for posts made by the current user?

Antechinus

Well you have to get up to speed with SMF lingo here. ;) The page you are reading this on right now is Display.template.php. The "message template" is MessageIndex.template.php, which is the one you see if you hit the "SMF coding Discussion" link in the linktree. I assume you want this page. No problem.

The one you want is $message['is_message_author']

That will allow you to call any markup you want for the post in question. An example is provided below.


// Show online and offline buttons? PHP could do with a little bit of cleaning up here for brevity, but it works.
// The plan is to make these buttons act sensibly, and link to your own inbox in your own posts (with new PM notification).
if ($context['can_send_pm'] && $message['is_message_author'])
{
echo '
<li class="pm_link ',$context['user']['unread_messages'] > 0 ? ' new_pm':'', '">
<a href="', $scripturl, '?action=pm">', $txt['pm_short'], '', $context['user']['unread_messages'] > 0 ? ' - <em>'. $context['user']['unread_messages']. ' '. $txt['new']. '!</em>' : '', '</a>
</li>';
}

samborabora

Lainaus käyttäjältä: Antechinus - kesäkuu 23, 2014, 05:55:53 IP
Well you have to get up to speed with SMF lingo here. ;) The page you are reading this on right now is Display.template.php. The "message template" is MessageIndex.template.php, which is the one you see if you hit the "SMF coding Discussion" link in the linktree. I assume you want this page. No problem.

The one you want is $message['is_message_author']

That will allow you to call any markup you want for the post in question. An example is provided below.


// Show online and offline buttons? PHP could do with a little bit of cleaning up here for brevity, but it works.
// The plan is to make these buttons act sensibly, and link to your own inbox in your own posts (with new PM notification).
if ($context['can_send_pm'] && $message['is_message_author'])
{
echo '
<li class="pm_link ',$context['user']['unread_messages'] > 0 ? ' new_pm':'', '">
<a href="', $scripturl, '?action=pm">', $txt['pm_short'], '', $context['user']['unread_messages'] > 0 ? ' - <em>'. $context['user']['unread_messages']. ' '. $txt['new']. '!</em>' : '', '</a>
</li>';
}


This is great, so far i have:
// For you
if ($message['is_message_author'])
{
echo '
<div class="cat_bar">
<h3 class="catbg">
<p>MEEEE</p>
</h3>
</div>
<div class="', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', '">
<span class="topslice"><span></span></span>
<div class="post_wrapper">';
}

// For them
if ($message['member'])
{
echo '
<div class="cat_bar">
<h3 class="catbg">
</h3>
</div>
<div class="', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', '">
<span class="topslice"><span></span></span>
<div class="post_wrapper">';
}


I'm just trying to figure out what I need to go just after // For them, I need it to really call for anyone who is not the logged in user, but I'm not sure what string this is? The code, in theory, SHOULD work if I get that line in correctly (and assuming guest posts are allowed, it accounts for that as well, depending on the string)

samborabora

What is the opposite variable to $message['is_message_author'], ie: what calls for if message is NOT psoted by the current user?

Morsyl

You can put a ! in front of the variable to test if it's not true.

Eg:
if(!$message['is_message_author'])

samborabora

#7
Lainaus käyttäjältä: Morsyl - kesäkuu 25, 2014, 07:39:13 IP
You can put a ! in front of the variable to test if it's not true.

Eg:
if(!$message['is_message_author'])

Thankyou!! This works perfect:

// For you
if ($message['is_message_author'])
{
echo '
<div class="cat_bar">
<h3 class="catbg">
MEEEE
</h3>
</div>
<div class="', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', '">
<span class="topslice"><span></span></span>
<div class="post_wrapper">';
}

// For them
if(!$message['is_message_author'])
{
echo '
<div class="cat_bar">
<h3 class="catbg">
</h3>
</div>
<div class="', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', '">
<span class="topslice"><span></span></span>
<div class="post_wrapper">';
}

Antechinus

No it doesn't. :D Minor point, but it will fail validation like that. You can't have a p inside an h3. The h series are for headings before paragraphs (or before something else). Just put your MEEE straight in the h3.

samborabora

Lainaus käyttäjältä: Antechinus - kesäkuu 27, 2014, 02:27:06 AP
No it doesn't. :D Minor point, but it will fail validation like that. You can't have a p inside an h3. The h series are for headings before paragraphs (or before something else). Just put your MEEE straight in the h3.
I've already changed it on my forum, I just removed the <p> tag, I'll fix my example, thanks for the suggestion!

Advertisement: