Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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).
Yes:
mydomain.com/?category=cat1,cat2,cat3
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.Id, tag, "cat1,cat2", author, searchTerm, commenter, page-1, count);
No posts are returned.
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.
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.Id, tag, "cat1", author, searchTerm, commenter, page-1, count);
var posts2 = PostService.Instance.GetPosts(Model.Id, tag, "cat2", author, searchTerm, commenter, page-1, count);
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.
This should do it:
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.
Thank you for your help. One last question, can I reorder the List according to postdate?
var ordered = posts.OrderByDescending(x => x.GetPropertyValue("uBlogsyPostDate"));
Is it possible to pass to category the list of categories?
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)
...........
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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).
Yes:
mydomain.com/?category=cat1,cat2,cat3
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.Id, tag, "cat1,cat2", author, searchTerm, commenter, page-1, count);
No posts are returned.
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.
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.Id, tag, "cat1", author, searchTerm, commenter, page-1, count);
var posts2 = PostService.Instance.GetPosts(Model.Id, tag, "cat2", author, searchTerm, commenter, page-1, count);
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.
This should do it:
var posts1 = PostService.Instance.GetPosts(Model.Id, tag, "cat1", author, searchTerm, commenter, page-1, count);
var posts2 = PostService.Instance.GetPosts(Model.Id, tag, "cat2", author, searchTerm, commenter, page-1, count);
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.
Thank you for your help. One last question, can I reorder the List according to postdate?
var ordered = posts.OrderByDescending(x => x.GetPropertyValue("uBlogsyPostDate"));
Is it possible to pass to category the list of categories?
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)
{
...........
}
is working on a reply...