User's avatar in Blog (default theme)

rated by 0 users
This post has 30 Replies | 4 Followers

Top 75 Contributor
Posts 247
Points 3,020
davelee Posted: Thu, Jun 29 2006 2:53 PM

Like the user's Gallery, which shows the user's avatar, I'd like to do the same in the default user's Blog.

I've copied the

<CS:UserAvatar runat="server" Border="0" PadImage="false" id="Avatar" />

from the Skin-GalleryTitleHeader.ascx and copied to the Skin-BlogTitleHeader.ascx, but it's not working.

The User in UserAvatar : UserInfo is coming up null.

Any thoughts as to why and how to fix?

 

David
Top 10 Contributor
Posts 3,424
Points 65,530
CS Developers
Ben Tiedt replied on Fri, Jun 30 2006 9:25 AM

You'll need to specify the User on the UserAvatar control -- you can do this using inline code, such as:

 <script language="C#" runat="server">
protected override void OnLoad (EventArgs e)
{
 if (((CommunityServer.Blogs.Controls.WeblogTemplatedWebControl) this.Parent).CurrentWeblog.OwnerArray.Length > 0)
  userAvatar.User = CommunityServer.Users.FindUserByUsername(((CommunityServer.Blogs.Controls.WeblogTemplatedWebControl) this.Parent).CurrentWeblog.OwnerArray[0]);
 else
  userAvatar.Visible = false;
}
</script>

where userAvatar is the ID of the UserAvatar control and you want to display the avatar of the owner of the blog.

Ben Tiedt's Blog

  • | Post Points: 50
Top 75 Contributor
Posts 247
Points 3,020
davelee replied on Fri, Jun 30 2006 12:30 PM

Got it...

Thanks Ben!

David
Not Ranked
Posts 14
Points 175
dcheung replied on Sun, Jul 30 2006 9:06 PM

I want to add a avatar on each post in Blog/Skin-AggregateList.ascx.

I have tried your solution, but it can't apply into Blog/Skin-AggregateList.ascx.

Would you give me some suggestion?

Thanks in advance.

Dennis.

  • | Post Points: 20
Top 10 Contributor
Posts 3,424
Points 65,530
CS Developers
Ben Tiedt replied on Mon, Jul 31 2006 10:07 AM

To show the avatar of the author of each post in the aggregate blog list, in Skin-AggregateList.ascx,

1.  Add the following anywhere (for example, at the top of the skin file after the <%@...> declarations):

<script language="C#" runat="server">
public CommunityServer.Components.User GetPostUser(CommunityServer.Components.Post post)
{
 if (post.User != null)
  return post.User;
 else if (post.UserID > 0)
  return CommunityServer.Users.GetUser(post.UserID, false);
 else
  return null;
}
</script>

2.  Add the following within the <ItemTemplate> of the <asp:Repeater id="Posts"> where you want the avatar to display:

<cs:UserAvatar runat="server" User='<%# GetPostUser ((CommunityServer.Components.Post) Container.DataItem) %>' />

 

Ben Tiedt's Blog

  • | Post Points: 35
Not Ranked
Posts 14
Points 175
dcheung replied on Mon, Aug 7 2006 3:49 AM

Thanks Ben Tiedt.

I can displayed the avatar now.

But I have another problem for redirect to user profile when onclick that avatar.

Could you give me some hints?

Dennis.

  • | Post Points: 20
Top 10 Contributor
Posts 3,424
Points 65,530
CS Developers
Ben Tiedt replied on Mon, Aug 7 2006 10:49 AM

To add a link around the avatar included using the changes listed above,

1.  Add the following within the existing <script language="C#" runat="server"> region  (created with the code above):

public string GetPostUserProfileUrl(CommunityServer.Components.Post post)
{
 if (post.User != null && !post.User.IsAnonymous)

    return CommunityServer.Components.SiteUrls.Instance().UserProfile(post.User.Username);
 else if (post.UserID > 0 && post.UserID != CommunityServer.Users.GetAnonymousUser(true).UserID)
  return CommunityServer.Components.SiteUrls.Instance().UserProfile(post.UserID);

return string.Empty;
}

2.  Add the following around the <cs:UserAvatar /> added as part of the change above:

<asp:HyperLink runat="server" NavigateUrl='<%# GetPostUserProfileUrl ((CommunityServer.Components.Post) Container.DataItem) %>'> <cs:UserAvatar /> </asp:HyperLink>

Ben Tiedt's Blog

  • | Post Points: 20
Not Ranked
Posts 14
Points 175
dcheung replied on Tue, Aug 8 2006 5:19 AM
its Working now. thx a lot.
  • | Post Points: 5
Not Ranked
Posts 30
Points 485
aous replied on Fri, Jan 5 2007 4:35 PM

Hi there

 

This solution is great until you decide to have Multiple Owners for each blog

 

"CurrentWeblog.OwnerArray[0]);" will get you the first Owner on the List.

 

Is there a way to get the Username with a different method?

 


 

  • | Post Points: 20
Top 10 Contributor
Posts 2,517
Points 28,655
MVPs
If you have multiple blog owners, who's avatar should be displayed?

Four Roads

  • | Post Points: 35
Not Ranked
Posts 30
Points 485
aous replied on Tue, Jan 9 2007 12:04 PM

we already fixed the problem.

by using  .CurrentWeblog.MostRecentPostAuthor

here is the idea behind this:

each Blog post can have multiple owners that can post, so the Avatar should have that spacific owner's image.

it is not the right way of doing it, but in our case the right owner was the most recent post auther.

Cheers
 

  • | Post Points: 5
Top 500 Contributor
Posts 48
Points 945
glgehman replied on Wed, Mar 28 2007 3:22 PM

Genyus:
If you have multiple blog owners, who's avatar should be displayed?

 

In the case of a blog with multiple owners, the displayed avatar should be the individual post's author.   So, if you and I both are owners of a blog and I post on Tuesday, my avatar should accompany my post.  If you post on Wednesday, your avatar would accompany your post.  This is how it happens in the forums.

  • | Post Points: 20
Not Ranked
Posts 30
Points 485
aous replied on Thu, Mar 29 2007 11:53 AM

to add the User Avatar to the Skin-AboutAuthor.ascx page do the following:

 

Script (add it after the <%@ Import part and before the HTML part)

 

 

<script id="Script1" runat="server" language="C#">
        protected override void OnPreRender(EventArgs e)
            {
            userAvatar.User = CommunityServer.Users.FindUserByUsername(UserName.Text);
            }
        </script>

 

HTML       

 

  <CS:UserAvatar runat="server" Border="0" PadImage="false" id="userAvatar" />

this is the easiest way of doing it, which is basically taking the username from the bio tag and populate the avatar with it on the Pre Render Event of the page.


 

 

  • | Post Points: 5
Not Ranked
Posts 11
Points 190
ggannon replied on Wed, May 9 2007 8:29 PM

Is this the same for CS07?

This is what I am trying to do...On the home page aggregate list(I have narrowed my list to Blogs only) I want to replace the "Blog" icon with the authors avatar...I also want the avatar to link to this their personal blog page(all users have a blog page).


I am very new to CS so the more detail in explaining this the better Smile

 Thanks so much

Gary
 

 

  • | Post Points: 20
Top 10 Contributor
Posts 3,424
Points 65,530
CS Developers
Ben Tiedt replied on Wed, May 9 2007 10:12 PM

In CS2007, the <CSControl:UserAvatar /> control can be placed anywhere within the context of a user (for example, placed within the context of a post, the post's author will be displayed).

The current blogs page on cs.org (http://communityserver.org/blogs/) users this markup as the <ItemTemplate> of the <CSBlog:WeblogPostList /> control to include the user's avatar in place of the blog icon:

<li class="BlogPostArea None">
    <div style="float: left; width: 70px;">
        <CSControl:UserAvatar runat="server" BorderWidth="1" Width="48" Height="48" />
    </div>
    <div style="float: left; width: 535px;">
        <CSBlog:WeblogPostData Property="Subject" LinkTo="Post" Tag="H4" CssClass="BlogPostHeader" runat="server" />
        <CSBlog:WeblogPostData Property="Excerpt" Tag="Div" CssClass="BlogPostContent" runat="server" />
        <div class="BlogPostFooter">
            <CSBlog:WeblogPostData Property="UserTime" LinkTo="Post" IncludeTimeInDate="true" Tag="Div" runat="server"><LeaderTemplate>Published </LeaderTemplate></CSBlog:WeblogPostData>
        </div>
    </div>
    <div style="clear: both;"></div>
</li>

Ben Tiedt's Blog

  • | Post Points: 50
Page 1 of 3 (31 items) 1 2 3 Next > | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com