I am using the out of the box Umbraco query builder to query posts that I have created. The query builder makes it very easy to query posts by creation date or updated date, but if i wanted to make a "featured post" section, how would I go about that? All of my blog posts have a tag section in their document type. In addition to relative keyword tags, I would also like to tag anything that I want to be "featured".
Ultimately I would like to pull in the latest 1-3 featured articles so they remain sticky at the top of my blog page. Some of these were created months ago so they don't get seen with the standard .CreateDate function. Any help would be appreciated. Thanks!
To show posts with a specific tag, you can use TagQuery and simple URL-based filtering, so when a user visits your-domain/blog?tag=featured only posts tagged with “featured” will be listed:
On the template that you use to list all the posts, you should be able to do something like this
var tag = Request.QueryString["tag"];
var articles = (tag != null)
? Umbraco.TagQuery.GetContentByTag(tag).OfType<NewsArticle>()
: Model
.Children<NewsArticle>()
.OrderByDescending(x => x.CreateDate).Take(3);
Remember you will need to replace bits and pieces so they match your document types and so on
Query posts by document tag
I am using the out of the box Umbraco query builder to query posts that I have created. The query builder makes it very easy to query posts by creation date or updated date, but if i wanted to make a "featured post" section, how would I go about that? All of my blog posts have a tag section in their document type. In addition to relative keyword tags, I would also like to tag anything that I want to be "featured".
Ultimately I would like to pull in the latest 1-3 featured articles so they remain sticky at the top of my blog page. Some of these were created months ago so they don't get seen with the standard .CreateDate function. Any help would be appreciated. Thanks!
Hi Mike,
What a great question you have here.
To show posts with a specific tag, you can use TagQuery and simple URL-based filtering, so when a user visits your-domain/blog?tag=featured only posts tagged with “featured” will be listed:
On the template that you use to list all the posts, you should be able to do something like this
Remember you will need to replace bits and pieces so they match your document types and so on
Hope this can give you an idea how you can do it
Best
/Dennis
is working on a reply...