1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.5 New Posts Sidebar - Creating A Link To Username

Discussion in 'Styling and Customization Questions' started by Dan Hawkins, Aug 22, 2016.

  1. Dan Hawkins

    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.png

    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: Aug 22, 2016
  2. Dan Hawkins

    Dan Hawkins Active Member

    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.png

    LOL


    EDIT -

    That's because it's linking to /members/ now - damn
     
  3. Dan Hawkins

    Dan Hawkins Active Member

    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 >.<
     
  4. Amaury

    Amaury Well-Known Member

    Code:
    <a href="{xen:link 'members/5/'}" class="username">Amaury</a>
    Modify it for your needs.
     
  5. wang

    wang Well-Known Member

    Replace this part of the code:

    HTML:
    {$thread.lastPostInfo.username}
    with this:

    HTML:
    <xen:username user="$thread" />
    and save the changes.
     
    Dan Hawkins likes this.
  6. Dan Hawkins

    Dan Hawkins Active Member

    This only works on per user basis, but thanks for trying mate!

    Winner, winner chicken dinner! Thank you muchly, sir! :)
     
    wang likes this.
  7. Dan Hawkins

    Dan Hawkins Active Member

    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: Aug 23, 2016
    wang likes this.

Share This Page