Copied to clipboard

Flag this post as spam?

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


  • Tim Woodward 16 posts 66 karma points
    Apr 16, 2012 @ 23:24
    Tim Woodward
    0

    Displaying posts from multiple categories

    Is it possible to list blog posts by multiple categories?

    It looks like PostService.Instance.GetPosts will only accept one category ID, I want to list posts from multiple categories (but not ALL of them).

     

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Apr 23, 2012 @ 01:04
    Anthony Dang
    0

    Yes:

    mydomain.com/?category=cat1,cat2,cat3

     

     

  • Tim Woodward 16 posts 66 karma points
    Apr 23, 2012 @ 14:40
    Tim Woodward
    0

    That appears to not work. Either as you have mentioned above or by going into the Razor and using:

    var posts PostService.Instance.GetPosts(Model.Idtag"cat1,cat2"authorsearchTermcommenterpage-1count);

    No posts are returned.


  • Tim Woodward 16 posts 66 karma points
    Apr 23, 2012 @ 14:43
    Tim Woodward
    0
  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Apr 24, 2012 @ 11:15
    Anthony Dang
    0

    Oops!

    My mistake.

    I thought I already implemented that. I had to do that for a client. I thought I already integrated it into ublogsy.

    #h5is

     

    A work around would be to split the category query string.

    Then in a for loop, call GetPosts iwth the current category.

     

     

  • Tim Woodward 16 posts 66 karma points
    Apr 24, 2012 @ 12:28
    Tim Woodward
    0

    Ah right. Can you tell me how I can concatenate all the different results together and then order by post date before displaying them?

    I would assume if I had two sets of nodes for example

    var posts1 PostService.Instance.GetPosts(Model.Idtag"cat1"authorsearchTermcommenterpage-1count);

    var posts2 PostService.Instance.GetPosts(Model.Idtag"cat2"authorsearchTermcommenterpage-1count);

    That Library.Concatenate isn't going to work as I think that's just a string concat right? Sorry I'm quite new to Razor.

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Apr 24, 2012 @ 12:52
    Anthony Dang
    0

    This should do it:

     

    var posts1 PostService.Instance.GetPosts(Model.Idtag"cat1"authorsearchTermcommenterpage-1count);

    var posts2 PostService.Instance.GetPosts(Model.Idtag"cat2"authorsearchTermcommenterpage-1count);

    var posts = new List<DynamicNode>();

    posts.AddRange(posts1);

    posts.AddRange(posts2);

     

    Note: because you'll have a different number of posts displaying, pagination needs to be tweaked.

     

  • Tim Woodward 16 posts 66 karma points
    Apr 24, 2012 @ 13:15
    Tim Woodward
    0

    Thank you for your help. One last question, can I reorder the List according to postdate?

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Apr 24, 2012 @ 14:09
    Anthony Dang
    0

    var ordered = posts.OrderByDescending(x => x.GetPropertyValue("uBlogsyPostDate"));

     

  • Biagio Paruolo 1583 posts 1814 karma points c-trib
    Apr 18, 2013 @ 14:28
    Biagio Paruolo
    0

    Is it possible to pass to category the list of categories?

  • Biagio Paruolo 1583 posts 1814 karma points c-trib
    Apr 18, 2013 @ 15:05
    Biagio Paruolo
    0

    I solved in this way:

    var tuttiposts = new List<DynamicNode>();

     

    var nodescategories = PostService.Instance.GetPosts(Model.Id);

            foreach (var n in nodescategories)

            {

                allCategories.AddRange(n.uBlogsyPostCategories.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));

            }

     

            // get only distinct categories

            IEnumerable<string> elencocategorie = allCategories.Distinct();

                

            if (elencocategorie.Count() > 0){

                        

                        foreach (var c in elencocategorie)

                        {

                            if ((!string.IsNullOrEmpty(c.Trim())) && (c!="News"))

                            {

                              var posts1 = PostService.Instance.GetPosts(Model.Id, tag, c, author, searchTerm, commenter, page-1, count);

         tuttiposts.AddRange(posts1);  

                            }

                        }

              }

     

     var orderedposts = tuttiposts.OrderByDescending(x => x.GetPropertyValue("uBlogsyPostDate")).Distinct().Take(count);

       @foreach (DynamicNode n in orderedposts)  

            {

             ...........

             }

Please Sign in or register to post replies

Write your reply to:

Draft