This project is read-only.

Read Blogposts within my module?

Topics: Customizing Orchard, Troubleshooting, Writing modules
Oct 20, 2013 at 11:26 PM
Heya all,

I'm trying to find a solution for my (I assume) rather easy problem. Howver, I'm not able to find a usefull source on the internet.

I want to be able to read BlogPosts (Ochard.Blogs) from a "certain" "blog type"within my own module. However, I can't get it to work. I've tried different approaches such as referencing Orchard.Blogs within my Module and Query with the ContentPart directly by using the ContentManger. Sadly that doesn't seem to work out, as the source isn't compiling in this case.
Type argument specification is redundant. Method "IContentQuery<ContentItem> Orchard.ContentManagement .ICOntentManager.Query() doesn't have parameters
What am I missing? Am I doing a wrong approach? What would be the correct approach? Thanks for your help.
Oct 21, 2013 at 2:22 AM
What do you mean by "certain blog type"?

There are many examples of how to use content manager queries in the source code, and also here:

var items = _contentManager.Query<TitlePart, TitlePartRecord>()
    .Where(t => t.Title.Contains("foo"))
    .OrderBy(r => r.Title)
    .Slice(10, 5);

Oct 21, 2013 at 12:13 PM
Edited Oct 21, 2013 at 1:13 PM

that's how I understood it as well, but it looks like that BlogPostPart doesn't have a BlogPostPartRecord, so I'm not ablet to query them directly.

What is giving me a result like I want it to have is:
            var blogs = _controller.OrchardServices.ContentManager.Query<BlogPart, BlogPartRecord>().List();

            var posts = new List<BlogPostPart>();

            foreach (var blog in blogs)
                if (blog.Name == "name")
                    var blogPosts =
                                   .Where(cr => cr.Container == blog.Record.ContentItemRecord)

                    foreach (var blogPost in blogPosts)
but I'm sure there's a easier way? :)
Oct 21, 2013 at 6:27 PM
I still don't understand what is a "specific blog". Do you have the Id of the blog? If have the blog content item, which should have a blogpart, there is one

public IEnumerable<BlogPostPart> Get(BlogPart blogPart)

in Orchard.Blogs.Services.BlogPostService class. You can call it in your module.