SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member Jason Web's Avatar
    Join Date
    Feb 2014
    Location
    USA
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Toggle User Profile Links

    Hello.

    I have managed to make user profile pages link to the registration page for unregistered visitors while also making them accessible for a registered logged in user.
    But, I am not sure how to do it including the avatar image link directly under the video where it shows the Avatar for the user that submitted the article and the text and link to user profile.

    I need help with this code. Part of it is right where it just shows the users text name as a link (Posted by). But the user's avatar link should be toggled also. Here is my code:

    PHP Code:
              <div style="padding: 0px 40px;" class="large justify">
              {
    user var=$user username=$video.username}
              {if 
    $user}
              <
    a href="{$g_config.base_uri}/profile/{$video.username}/"><img src="{if $user.uri}{$user.uri}{else}{$g_config.template_uri}/images/media-avatar.jpg{/if}" alt="{$video.username}'s Profile" style="max-width: 50px; max-height: 38px; border: 1px solid black; display: inline-block; margin-right: 8px;" /></a>
              {/if}
              <
    span style="display: inline-block; vertical-align: top;">
                <
    div class="larger bold">{$video.title}</div>
                <
    div class="video-brief-date smallest normal">Posted
                    
    {if $video.username}
                    
    by
                    
    {nocache}
                    {if 
    $g_logged_in}
                    {/
    nocache}
                    <
    a href="{$g_config.base_uri}/profile/{$video.username}/"><em>{$video.username}</em></a>
                    {
    nocache
                    {else}
                    <
    a href="http://www.site.net/user/login/" title="View User Profile"><em>{$video.username}</em></a>
                    {/if}
                    {/
    nocache}
                    {/if} 
    on {$video.date_added|t_datetime}.</div>
              </
    span>
              </
    div>

              <
    div style="padding: 0px 40px;" class="largest justify">{$video.description|rawhtml}</div>
              
              {if 
    count($clips) > 1}
              <
    div id="clips">
                <
    b>Related Media Clips:</b><br />
                {foreach var=
    $clip from=$clips}
                  <
    img src="{if $clip.thumbnail}{$clip.thumbnail}{else}{$g_config.no_preview}{/if}" href="{$clip.clip}/>
                {/foreach}
              </
    div>
              {/if}

              <
    br /> 

  2. #2
    SitePoint Member Jason Web's Avatar
    Join Date
    Feb 2014
    Location
    USA
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sorry I did not leave a link to the page in question. I guess that would help of course
    Also, I must say that I have very little knowledge in PHP. And I hope I posted in the right area. Any help would greatly be appreciated.

    Here is the test page in question regarding the above mentioned code. As yo ucan see directly below the video, there is the Title of the article and the the information about date posted and by whom. The user link that posted it should goto the registration page. Along with the Avatar image next to the Title.

    Then if you notice further down the page where a comment response has been made. The same will be done with those user links. So that if the user is not logged in those links will goto the registration page. And when they are logged in theywill goto the users profile page. Any help with this would be greatly appreciated. I know this is my first post but is has really been nagging me on how to fix this to make it right. Another question about this code, and I see this tag used a lot in php it seems, what is URI? As in $g_config.base_uri. I understand the $g_config.base_url, but the uri still evades me.

    Thank you for any help that you may be able to offer. Or please let me know if I am not asking in the right area or asking improper questions. Thank you.

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,492
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Are you using some kind of template system?

    Anyway, I guess you want something like this (see the part in red):

    Code:
              <div style="padding: 0px 40px;" class="large justify">
              {user var=$user username=$video.username}
              {if $user}
                    {if $g_logged_in}
                    <a href="{$g_config.base_uri}/profile/{$video.username}/"><img src="{if $user.uri}{$user.uri}{else}{$g_config.template_uri}/images/media-avatar.jpg{/if}" alt="{$video.username}'s Profile" style="max-width: 50px; max-height: 38px; border: 1px solid black; display: inline-block; margin-right: 8px;" /></a>
                    {else}
                    <a href="http://www.site.net/user/login/"><img src="{if $user.uri}{$user.uri}{else}{$g_config.template_uri}/images/media-avatar.jpg{/if}" alt="{$video.username}'s Profile" style="max-width: 50px; max-height: 38px; border: 1px solid black; display: inline-block; margin-right: 8px;" /></a>
                    {/if}
              {/if}
              <span style="display: inline-block; vertical-align: top;">
                <div class="larger bold">{$video.title}</div>
                <div class="video-brief-date smallest normal">Posted
                    {if $video.username}
                    by
                    {nocache}
                    {if $g_logged_in}
                    {/nocache}
                    <a href="{$g_config.base_uri}/profile/{$video.username}/"><em>{$video.username}</em></a>
                    {nocache} 
                    {else}
                    <a href="http://www.site.net/user/login/" title="View User Profile"><em>{$video.username}</em></a>
                    {/if}
                    {/nocache}
                    {/if} on {$video.date_added|t_datetime}.</div>
              </span>
              </div>
    
              <div style="padding: 0px 40px;" class="largest justify">{$video.description|rawhtml}</div>
              
              {if count($clips) > 1}
              <div id="clips">
                <b>Related Media Clips:</b><br />
                {foreach var=$clip from=$clips}
                  <img src="{if $clip.thumbnail}{$clip.thumbnail}{else}{$g_config.no_preview}{/if}" href="{$clip.clip}" />
                {/foreach}
              </div>
              {/if}
    
              <br />
    You'll have to test it though.
    And I have no idea what those {nocache} and {/nocache} are needed for, you might need to add some of those too, who knows

  4. #4
    SitePoint Member Jason Web's Avatar
    Join Date
    Feb 2014
    Location
    USA
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help.

    Yes, I am using a server script that uses .tpl files for all the pages. There is an editor for them all in the admin area.

    I have replaced it with your code. It works, but, now it doesn't show the user profile image. There is an image specified for default, yet it does not show.
    I have tried a couple different changes to try and get it to work including the nocache tags. But still nothing.

    This is code I have now. The code you gave has the same effect:
    PHP Code:
    {user var=$user username=$video.username}
              {if 
    $user}
                    <
    nocache>
                    {if 
    $g_logged_in}
                    </
    nocache>
                    <
    a href="{$g_config.base_uri}/profile/{$video.username}/"><img src="{if $user.uri}{$user.uri}{else}{$g_config.template_uri}/images/media-avatar.jpg{/if}" alt="{$video.username}'s Profile" style="max-width: 50px; max-height: 38px; border: 1px solid black; display: inline-block; margin-right: 8px;" /></a>
                    <
    nocache>
                    {else}
                    <
    a href="http://www.unexplainedmedia.net/user/login/"><img src="{if $user.uri}{$user.uri}{else}{$g_config.template_uri}/images/media-avatar.jpg{/if}" alt="{$video.username}'s Profile" style="max-width: 50px; max-height: 38px; border: 1px solid black; display: inline-block; margin-right: 8px;" /></a>
                    {/if}
                    </
    nocache>
              {/if} 
    Still stumped. I have a couple different user vars to work with. $user.name is the users Name. $video.username is the user login name that uploaded the associated article. $user.uri is the specified avatar image for the user {if} one is provided. If not it should use the default. Yet it shows no image.

    Thank you so much for your help!

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,492
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    I don't think it's a problem with the script. The link to the avatar is

    http://www.unexplainedmedia.net/temp...dia-avatar.jpg

    and it seems that image is missing?

  6. #6
    SitePoint Member Jason Web's Avatar
    Join Date
    Feb 2014
    Location
    USA
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm .. Yes it does seem that the image is missing. Which is weird since it was working previously. Which is why I did not check that. Thanks you! ... I'm looking into it and will let you know.

  7. #7
    SitePoint Member Jason Web's Avatar
    Join Date
    Feb 2014
    Location
    USA
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have it fixed! Thank you so much for your help! ... What stumped me from the beginning was the unknown of being able to use more than one {if} inside each other.

    Now I have to try and implement this with the user comments area.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •