Add blog content to pages

Aug 22, 2008 at 5:58 PM
Edited Aug 22, 2008 at 6:00 PM
I need to accomplish the following.

I have a web site with several bloggers. Each blogger has his/her own page.  On their individual page I would like to have some static content followed by their own blog posts.


How might I accomplish this. 

The blog is a work in progress, you can visit it here to get an idea of what I'm trying to do:  www.cubscoutpack55.com So, for instance, if you click on the "Tiger", "Bear" link, you would see only the blog posts (following some static content) for that author of the Tiger blog. Know what I mean?

Thanks.
Aug 24, 2008 at 12:07 PM
This is a little bit tricky. You could do it by using User control injection which came about with version 1.2. You want to inject a Post List control into your user pages. However, you need to craft the control yourself to only show the posts by the user but you can take advantage of the ~/User controls/PostList.ascx user control.

Another way to get something like what you want is to link to the individual user's posts i.e. /author/<user>.aspx which lists the posts by <user>.

Hope that what somewhat helpful.

Rickard Nilsson
http://rickardnilsson.net
Aug 25, 2008 at 12:08 PM
Take a look at http://www.codeplex.com/ASPNETRSSToolkit. I think you may find it very useful for what you are trying to accomplish.
Aug 25, 2008 at 5:03 PM
Rickard,

  Thanks for the reply.

>> However, you need to craft the control yourself to only show the posts by the user but you can take advantage of the ~/User controls/PostList.ascx user control.  <<

I just may try that. I'm thinking of modifying the code to check for a parameter on the QueryString "Author" in which case it will filter Posts not by that author.  I'm not sure whether I should modify the PostList control itself. If I did, is this something that I should contribute to the code base?

 -- xavier
Aug 25, 2008 at 5:38 PM
Ok, so I've got the PostList control to filter out based on a user. The key is telling the control to do so.  In the injected markup, I see no way of indicating so (as one can't pass a parameter to a user control). One approach is to add an entry in the Web.Config that assigns a page to a PostList control.  Here's what I prefer. I would like to be able to do the following with Usercontrol injection

[usercontrol:~/User controls/PostList.ascx author:user1]

what do you think? 

For a quick and dirty solution for now (because I need one) I'm going with the web.config approach. I may consider the other approach later.

 -- xavier
Aug 25, 2008 at 8:49 PM
Edited Aug 25, 2008 at 8:52 PM
@xavier That is exactly what you can do! From version 1.3 of BlogEngine.NET you can have properties in your User control injections allmost like you wrote. It goes like this:

[Usercontrol: ~/MyPostList.ascx Author=user1]

Where the property Author maps to the public property Author in the User control. The problem is that the PostList.ascx does not have an Author property. So, you need to wrap it up in your own User control, adding a Author property and tweeking it such that you get the behavior you need.

Read more at http://blog.madskristensen.dk/post/Examples-on-new-BlogEngineNET-13-features.aspx and look at this video on User control injection.

/Rickard
http://rickardnilsson.net
Aug 25, 2008 at 9:01 PM
Sweet! 

I modified the Postlist.ascx control as follows:

I added the following propery:

    private string _Author = string.Empty;
    /// <summary>
    /// The name of the author to filter against.
    /// </summary>
    public string Author
    {
        get { return _Author; }
        set { _Author = value; }
    }


Then modified the beginning of the bindposts method to contain:

        if (Posts == null || Posts.Count == 0)
        {
            if( _Author != string.Empty && Post.GetPostsByAuthor( _Author ).Count > 0)
            {
                Posts = Post.GetPostsByAuthor( _Author ).ConvertAll( new Converter<Post, IPublishable>( delegate( Post p ) { return p as IPublishable; } ) );
            }
            else
            {
                hlPrev.Visible = false;
                return;
            }
        }


Now, I'd rather get this into the code base then have my own control.  How would I go about doing that?

 -- xavier
Aug 25, 2008 at 9:08 PM
Well, as far as I'm conserned, that is really not the intent of the PostList user control. Rather a specialization of the same, and thus it should belong in a separate control. However, I have no say in what goes into the code base what so ever.

/Rickard
Aug 25, 2008 at 9:15 PM
Ok, thanks for your help Rickard, you totally got me on the right track!
 -- x