XF 1.5 New Posts Sidebar - Creating A Link To Username

Dan Hawkins

Active member
Hi Guys,

Trying to link usernames to the profiles - opening them in the overlay....

Code:
            <div class="additionalRow muted">
                {xen:phrase latest}: <a href="members/{$thread.lastPostInfo.username}"
                                class="username">{$thread.lastPostInfo.username}</a>, <xen:datetime time="$thread.lastPostInfo.post_date" />
            </div>

As you can see I've added in some custom code to try and link the username, but this creates the following error:

upload_2016-8-22_22-39-51.webp

Looking into it deeper, I can see this:

<xen:foreach loop="$threads" value="$thread">

on the New Posts Sidebar - but the "Members Online Now" box uses this:
<xen:foreach loop="$onlineUsers.records" value="$user" i="$i">

How can I get the loop to ALSO include the onlineusers.records and value ?

I've tried this *lol* (as you can tell, PHP isn't my strong point at this point in time (training coming soon), CSS anyday)

Code:
<xen:foreach loop="$onlineUsers.records" value="$user" i="$i">
            <div class="additionalRow muted">
                {xen:phrase latest}: <a href="members/{$thread.lastPostInfo.username}"
                                class="username">{$thread.lastPostInfo.username}</a>, <xen:datetime time="$thread.lastPostInfo.post_date" />
            </div>
</xen:if>

Alternatively, how can I make the link work? Am I missing something stupidly easy here?

Any help would be appreciated!

Cheers,

Dan
 
Last edited:
Update 1:

I tried this code:
Code:
            <div class="additionalRow muted">
                {xen:phrase latest}: <a href="{xen:link members, $thread.lastPostInfo.username}"
                                class="username">{$thread.lastPostInfo.username}</a>, <xen:datetime time="$thread.lastPostInfo.post_date" />
            </div>

and got this:
upload_2016-8-22_22-48-51.webp

LOL


EDIT -

That's because it's linking to /members/ now - damn
 
Doh - I just spotted where I went wrong....

New code:
Code:
            <div class="additionalRow muted">
                {xen:phrase latest}: <a href="{xen:link members, $user}"
                                class="username">{$thread.lastPostInfo.username}</a>, <xen:datetime time="$thread.lastPostInfo.post_date" />
            </div>

NOPE - This doesn't actually work, this just causes ALL usernames in the list to reference the same user profile.

Any help would be appreciated >.<
 
Replace this part of the code:

HTML:
{$thread.lastPostInfo.username}

with this:

HTML:
<xen:username user="$thread" />

and save the changes.
Just to update you - I tried your suggestion, however there were inconsistencies and random users appearing by unrelated threads..... I changed the code to this:

Code:
<xen:username user="$thread.lastPostInfo" />

This brought more accurate information and reliable links back to the correct poster (name didn't match avatar, but it does now).

But thank you massively for giving me the right bit of code to be working with!

Cheers,

Dan
 
Last edited:
Top Bottom