Take the 2-minute tour ×

I'm trying to filter the Archive Blog posts by Taxonomy Terms.

I have added a Taxonomy filed called Category to the Blog Post Content type, this Taxonomie has about 4-5 terms (no sub levels).

Eventually I want to do this dynamically, using an ajax post in a custom module. and filtering on multiple terms, for now I am trying to filter the archive post results by one term only

For now I am just looking to filter the results of the ListByArchive method in BlogPostsController. just to see it work, then I'll move my code.

I've added an instance on ITaxonomyService to the BlogPostController,

and tried to filter the result.

    public class BlogPostController : Controller {
        private readonly IOrchardServices _services;
        private readonly IBlogService _blogService;
        private readonly IBlogPostService _blogPostService;
        private readonly IFeedManager _feedManager;
        private readonly IArchiveConstraint _archiveConstraint;
        private readonly ITaxonomyService _taxonomyService;

        public BlogPostController(
            IOrchardServices services, 
            IBlogService blogService, 
            IBlogPostService blogPostService,
            IFeedManager feedManager,
            IShapeFactory shapeFactory,
            IArchiveConstraint archiveConstraint, 
            ITaxonomyService taxonomyService) {
            _services = services;
            _blogService = blogService;
            _blogPostService = blogPostService;
            _feedManager = feedManager;
            _archiveConstraint = archiveConstraint;
            _taxonomyService = taxonomyService;
            T = NullLocalizer.Instance;
            Shape = shapeFactory;

        dynamic Shape { get; set; }
        public Localizer T { get; set; }

        public ActionResult ListByArchive(string path) {

            var blogPath = _archiveConstraint.FindPath(path);
            var archive = _archiveConstraint.FindArchiveData(path);

            if (blogPath == null)
                return HttpNotFound();

            if (archive == null)
                return HttpNotFound();

            BlogPart blogPart = _blogService.Get(blogPath);

            if (blogPart == null)
                return HttpNotFound();

            var list = Shape.List();

            var posts = _blogPostService.Get(blogPart, archive);

            var tax = _taxonomyService.GetTaxonomyByName("Category");

            var term = _taxonomyService.GetTermByName(tax.Id, "Development"); 

            var filter = posts.Where(p => p.ContentItem.As<TermsPart>().Terms.Contains(term));

            var range = filter.Select(b => _services.ContentManager.BuildDisplay(b, "Summary"));



            dynamic viewModel = Shape.ViewModel()

            return View((object)viewModel);

However the term above is a TermPart,

the Terms of TermsPart are TermContentItems.

How can I convert form one to the other, compare them in a linq query, or how are the two related?

share|improve this question
All parts have a ContentItem property, and content items can be cast to a specific part using As<thePartType>(). But I'm curious about why you don't start from the terms, using the taxonomy service's GetContentItems method? –  Bertrand Le Roy Oct 25 '12 at 18:01
I want to filter by Date as well as Taxonomy as you can see here riders-test.apphb.com/news –  Axe Oct 25 '12 at 18:17
I followed Bertrand Le Roy's suggestion, you can see an example here stackoverflow.com/questions/13089185/… –  Axe Oct 29 '12 at 16:42
add comment

Your Answer



Browse other questions tagged or ask your own question.