in

jetlounge

the minty fresh blog that whitens your teeth!


Syndication


Change the Number of Recent Posts on the CS Home Page

by David Leibowitz | December 7, 2007 | Comments: 0

Community Server 2007.1 provides the default capability to show the most “recent posts” on the home page view. It deems “recent”, by default as the last 10 days and will pull the Top 5 articles. But what if you wanted to display more (or less) than 5? And what if the 10 day window wasn’t to your liking?

 

What strikes me as odd, is that for an application that provides for so much scalability with an ASP master page layout, table based controls, and an administrative interface where you maintain parameters that control the entire business logic and layout of the application…why would they tuck away such a seemingly important nugget in some hard-coded C# in the master page itself??

 

Things that make you go hmm.

 

OK, so to change these defaults go to the home.aspx page in your theme directory like

~\[theme]\common\home.aspx 

You’ll notice a block of code towards the top:

 
<script language="C#" runat="server">    
       void Page_Load()   
{
       
      
SetTitle(CurrentCSContext.SiteSettings.SiteName, false);
   
}
    
protected override void OnInit(EventArgs e)
   
{
        List<IndexPost> recentPosts = CSCache.Get("HomePageSearch-" + CurrentCSContext.User.RoleKey) as List<IndexPost>;
        if (recentPosts == null)
        {            SearchQuery query = new SearchQuery();
            query.StartDate = DateTime.Now.AddDays(-10);
            query.EndDate = DateTime.Now.AddDays(1);
            query.PageSize = 5;
            recentPosts = CSSearch.Search(query).Posts;
            CSCache.Insert("HomePageSearch-" + CurrentCSContext.User.RoleKey, recentPosts, CSCache.MinuteFactor * 5);
        }
        RecentPostList.DataSource = recentPosts;
        base.OnInit(e);
    }
</script>
   

If you want to change the default number of days to 200, change  the line:

                 query.StartDate = DateTime.Now.AddDays(-10);

to

                query.StartDate = DateTime.Now.AddDays(-200);  

If you’d like to display 10 articles instead of 5, change the line:

                 query.PageSize = 5; 

to

                query.PageSize = 10;

  del.ico.us digg this technorati BlinkList Furl reddit DotNetKicks google! live Facebook Stumble Upon Yahoo!



Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
Powered by Community Server (Non-Commercial Edition), by Telligent Systems