Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anuj 15 posts 35 karma points
    Mar 07, 2012 @ 12:15
    Anuj
    0

    Group by Category

    Hi,

    I am working on UBlogsy from last 3 days.I am facing one issue.Is it possible to group posts according to category on home page.

    For example following are the post:

    Post                      category

    test1                      category1

    test2                      category1

    test3                      category2

     

    Now i wanna show :

    Categories: Category1

    test1

    test2

    Categories: Category2

    test3

    So can we group post?

     

    Thanks

    Anuj

     

     

     

     

     

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Mar 07, 2012 @ 13:46
    Anthony Dang
    0

    You can do anything...

    Take a look at the uBlogsyListCategories.cshtml

    This will show you how to get all the categories.

     

    In uBlogsyListPosts.cshtml (or a copy of that file), once you have the categories you can get posts by category 

    foreach (var category in categories){

    var posts = PostService.Instance.GetPosts(Model.Id, string.Empty, category,  string.Empty ,  string.Empty ,  string.Empty , 0, ITEMS_PER_PAGE);

    // insert your markup here

    }

     

  • Anuj 15 posts 35 karma points
    Mar 07, 2012 @ 14:57
    Anuj
    0

    Thanks for quick reply.Could you please tell me how can i get categories.
    else
        { 
          
             
            // get tag, category, or author from query string
            var tag = Request.QueryString["tag"];
            var category = Request.QueryString["category"];
            var author = Request.QueryString["author"];
            var searchTerm = Request.QueryString["search"];
            var commenter = Request.QueryString["commenter"];
            int page = int.TryParse(Request.QueryString["page"], out page) ? page : 1;

    }

     Its showing empty  category.

     

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Mar 07, 2012 @ 17:09
    Anthony Dang
    0

    The code you're looking at is for getting the category from the query string.

     

    Don't you just want to list all the categories and posts with that category?

    Take a look at the uBlogsyListCategories.cshtml

    There is a for loop which lists categories. 

    For each of those categories, instead of rendering the category, you want to use this:

    foreach (var category in categories){

      var posts = PostService.Instance.GetPosts(Model.Id, string.Empty, category,  string.Empty ,  string.Empty ,  string.Empty , 0, ITEMS_PER_PAGE);

      // insert your markup here

    }

     

    But you want all of this either in uBlogsyListPosts, or in another cshtml file. eg uBlogsyListPostsByCategory

     

  • Anuj 15 posts 35 karma points
    Mar 14, 2012 @ 08:19
    Anuj
    0

    Hi,

    Sorry for late reply, i want to show posts group by category in uBlogsyShowPost.cshtml.

    Thanks

  • Anuj 15 posts 35 karma points
    Mar 15, 2012 @ 09:00
    Anuj
    0

    Hi Anthony,

     

    I have done this.I have created new cshtml file and embeded my own code and its working fine.Now i have another issue.Could you please tell me how to get most recent post.

     

    Thanks.

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Mar 15, 2012 @ 23:29
    Anthony Dang
    0

    There's a few ways that comes to mind

    Here's the first 

    var posts = PostService.Instance.GetPosts(Model.Id, string.Empty, string.Empty,  string.Empty ,  string.Empty ,  string.Empty , 0, 1);

    var post = posts.FirstOrDefault();


Please Sign in or register to post replies

Write your reply to:

Draft