Copied to clipboard

Flag this post as spam?

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


  • Heather 20 posts 41 karma points
    Apr 04, 2013 @ 17:01
    Heather
    0

    Show all posts except from one category

    Hello, bit of an odd request but here we go.

    On our clients blog, he would like to show all blog posts except from one category.

    Eg, list posts from

    • Category A
    • Category C

    To see posts from Category B, then you have to go to our-blog/?category=Category+B only.

    I was playing around with uBlogsyListPosts.chtml and was wondering if I can add a condition:

    var category = Request.QueryString["category"];
     if (string.IsNullOrEmpty(category))
            {
                category = everything but Category B
            }

     

    Would this be possible? Thanks for any help!

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Apr 04, 2013 @ 17:42
    Anthony Dang
    0

    For a small-ish site you could do another GetPosts() - NOT the one with many parameters - which will get all the posts.

    Then iterate over the allPosts, and remove the nodes that appear in the original posts list.

    You will have to do a .ToList() on the 

    If performance is a problem you will have to use lucene.

     

     

  • Heather 20 posts 41 karma points
    Apr 04, 2013 @ 18:10
    Heather
    0

    Thanks Anthony.

    How would I iterate through the posts?

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Apr 04, 2013 @ 18:31
    Anthony Dang
    0

    If you take a look at uBlogsyListPosts you'll see a for loop. Use that as a guide.


  • Biagio Paruolo 1619 posts 1912 karma points c-trib
    Apr 18, 2013 @ 14:32
    Biagio Paruolo
    0

    My solution:  

     

    @foreach (DynamicNode n in nodes)

            {

      allCategories.Clear();

      var categories = n.GetProperty("uBlogsyPostCategories").Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                   allCategories.AddRange(categories);

      flag=true;

               foreach (var c in allCategories)

                        {

                            if (!string.IsNullOrEmpty(c.Trim()))

                            {

    if (c=="News"){

    flag=false;

    }

                            }

                        } 

    if (flag){

       < something to do >

     } 

Please Sign in or register to post replies

Write your reply to:

Draft