More in this section

Forums / Developing with Sitefinity / Most Recent Categories

Most Recent Categories

5 posts, 0 answered
  1. Shane
    Shane avatar
    11 posts
    Registered:
    24 Aug 2007
    17 Apr 2008
    Link to this post
    I am using the blog categories on my site.  When I click a blog category is displays all the blog posts in that category.  The very first one in the list is the oldest blog post for that category.  Is there a way to have it display the most recent blog post in that category?

     I am using 3.1 sp2 standard

    Thanks,
    Shane
  2. Rebecca
    Rebecca avatar
    536 posts
    Registered:
    24 Sep 2012
    18 Apr 2008
    Link to this post
    Hello Shane,

    Please make sure you have set the SortExpression property to Publication_Date DESC.
    This is how to do it:
    1. Click Edit in the Blog Posts control header.
    2. Expand section Filters.
    3. Find SortExpression and set it to Publication_Date DESC.

    Let us know if you need any further assistance.

    All the best,
    Rebecca
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Shane
    Shane avatar
    11 posts
    Registered:
    24 Aug 2007
    18 Apr 2008
    Link to this post
    Hi Rebecca,

    Thanks for the response.

    The Blog lists all the post in the descending order.  That's what I want.
    It's the blog category list that has the problem.

    Example:

    http://www.guitarsocial.com/blog.aspx?CategoryID=2bc2812b-802a-4bf9-abe0-55189fcd4190

    This is the category view.  The oldest blog post is at the top of the page.  I want the newest blog post at the top of the page.

    Can this be changed?

    Thanks,
    Shane




  4. Shane
    Shane avatar
    11 posts
    Registered:
    24 Aug 2007
    23 Apr 2008
    Link to this post
    So I take it that this can't be changed?

    If this is the case than can you consider having a way to change the order of the category Blog post list in a future build?

    The way it's setup now doesn't make any sense.  Maybe it's just me but why would you want to show someone the oldest Blog post in a category when they click a category link.

    Shane
  5. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    24 Apr 2008
    Link to this post
    Hi Shane,

    You are absolutely right that sort expression should be applied, regardless of wheter the control shows all posts or just ones belonging to a specific category. We are going to have this fixed for the next release. In the mean time, I am going to provide you with a temporary solution and hopefully arm you with the knowledge to tweak the BlogPosts control as much as you want.

    Basically, the idea is the following: You create a new custom control, inherit the BlogPosts control and override the IList CreateDataSourceByCategory(Guid categoryID) method. At the moment, this method is missing sort expression, but you add it inside. Here is the code of this new control:

    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    using System.Collections;  
     
    using Telerik.Blogs.WebControls;  
    using Telerik.Cms.Engine;  
    using System.ComponentModel;  
     
    namespace BlogPostsPatch  
    {  
        [Category("Blogs"), DisplayName("BlogPosts Patch")]  
        public class BlogPostsPatch : BlogPosts  
        {  
     
            // fixes for the create data source by category - added support for filtering  
            protected override IList CreateDataSourceByCategory(Guid categoryID)  
            {
                #region Parameter validation  
     
                if (categoryID == Guid.Empty)  
                    throw new ArgumentNullException("categoryID");
                #endregion  
     
                // Get the ICategory object by its ID  
                ICategory category = this.Manager.GetCategory(categoryID);  
     
                // Get a collection of IContent object by category's name  
                // and make sure that no items are displayed with Publication_Date > Now  
                // - apply sort expression  
                IList contentList = new List<IContent>();  
                if (category != null)  
                {  
                    if (this.Manager.MetaKeys.ContainsKey("Publication_Date"))  
                    {  
                        IMetaSearchInfo[] filter = new IMetaSearchInfo[] { new MetaSearchInfo(MetaValueTypes.ShortText, "Category", category.CategoryName), new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", DateTime.Now, SearchCondition.LessOrEqual, JoinType.And) };  
                        contentList = this.Manager.GetContent(0, 0, base.SortExpression, nullthis.ParentIDs, filter);  
                    }  
                    else 
                    {  
                        IMetaSearchInfo[] filter = new IMetaSearchInfo[] { new MetaSearchInfo(MetaValueTypes.ShortText, "Category", category.CategoryName) };  
                        contentList = this.Manager.GetContent(0, 0, base.SortExpression, nullthis.ParentIDs, filter);  
                    }  
                }  
                else 
                {  
                    throw new ArgumentException("No category found for Category ID = " + categoryID.ToString());  
                }  
     
                return contentList;  
            }  
     
        }  

    In a similar manner you can override many other methods and so customize the behavior of BlogPosts control.

    I just wanted to say once again that we are going to fix this for a next release. But I thought I'd provide you with a quick workaround.

    Let us know if you have any other questions.

    Regards,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
5 posts, 0 answered