Blog Categories & Archives
I have 3 blogs setup in Sitefinity 4.0 for a client. I'm using the Category & Archive widget to display the categories & archives. I've used the Content Type of Telerik.Sitefinity.Blogs.Model.BlogPost.
Problem is the category & archive widgets are showing all of the blog categories & archives. How can I have each blog only display it's own categories & archives?
Thanks,
Brian
Hello Brian,
There is no implementation out of the box that you can use to achieve your goal. I logged a task with ID 111360 in our internal system and on the next planning we are going to discuss if we will be able to implement a property that allows you filtering by parent ID. Then we will add the task to PITS so you can use the ID I gave you to monitor the status. There is a way to filter by parent in a custom control that inherits from
Telerik.Sitefinity.Web.UI.PublicControls.ArchiveControl
There is a virtual method ConstructArchiveItems which you can override and filter the items returned by
var items = manager.GetArchieveItems(contentType, this.Provider, this.DateBuildOptions, this.DateEvaluatorPropertyName);
Kind regards,
Ivan Dimitrov
the Telerik team
Ivan,
Would you be able to provide me with a custom control example for filtering out blog categories & archives based on the different blogs?
I really have no idea how to get this working & am kinda in a crunch to get this fixed.
Thanks for any help you can provide!
Brian
Hi Brian,
Here is a sample code
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Telerik.Sitefinity.Web.UI.PublicControls;
using
System.Web.UI.WebControls;
using
Telerik.Sitefinity.Web.UrlEvaluation;
using
System.Web.UI;
using
Telerik.Sitefinity.Modules.GenericContent;
using
Telerik.Sitefinity.Utilities.TypeConverters;
namespace
Telerik.Sitefinity.Samples
public
class
ArchiveControlCustom : ArchiveControl
protected
override
void
InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
RenderTitle();
this
.dateRangeValues = GetDateRangeValues();
ConstructArchiveItems();
protected
virtual
void
ConstructArchiveItems()
var manager = ContentManager.GetManager();
if
(
this
.ContentType !=
null
)
var contentType = ResolveContentType();
// here get the items you need and bind the repeater control that will show only single blog items
var items = manager.GetArchieveItems(contentType,
this
.Provider,
this
.DateBuildOptions,
this
.DateEvaluatorPropertyName);
internal
virtual
Type ResolveContentType()
var contentType = TypeResolutionService.ResolveType(
this
.ContentType);
if
(contentType ==
null
)
throw
new
ArgumentException(String.Format(
"Content type \"0\" cannot be resolved."
,
this
.ContentType));
return
contentType;
internal
bool
IsDateInRange(DateTime t)
var result =
false
;
if
(
this
.dateRangeValues.Count > 0)
var from = dateRangeValues[0];
var to = dateRangeValues[1];
result = t.IsDateInRange(from, to);
return
result;
internal
virtual
void
RenderTitle()
var placehodler =
this
.Container.GetControl<PlaceHolder>(
"plhTitle"
,
false
);
if
(!String.IsNullOrEmpty(
this
.Title))
placehodler.Visible =
true
;
TitleLabel.Text =
this
.Title;
else
placehodler.Visible =
false
;
internal
virtual
List<DateTime> GetDateRangeValues()
var evaluator = UrlEvaluator.GetEvaluator(
"Date"
);
var values =
new
List<DateTime>();
if
(!
this
.IsDesignMode())
var url =
this
.Page.Request.Url.AbsolutePath;
(evaluator
as
DateEvaluator).Evaluate(url,
this
.DateEvaluatorPropertyName,
this
.GetUrlEvaluationMode(),
this
.UrlKeyPrefix,
out
values);
return
values;
private
List<DateTime> dateRangeValues;
I too would appreciate to have this functionality included in the next build of SF. One of my sites has 'public' content as well as 'secure' content contained within 2 separate blogs. I'd like to categorize posts within each and not have 'secure' content included within the 'public' category list and visa versa.
Hello David Muir,
You can create a new classification in the system by visiting the Content-> All Classifications options. Once you create the classification you want, you can create a custom field in the blog posts that let's you choose your private/public classification hierarchy. As for the public side, you can drop the Categories widget and show only the classification you want.
Please let me know if you have any difficulties applying the example above for your scenario.
Thank you very much for your assistance! But I have a couple questions, still:
You said #1: Once you create the classification you want, you can create a custom
field in the blog posts that let's you choose your private/public
classification hierarchy.
My Response to #1: I've created the new 'secure categories' classification. But I'm wanting to use it exactly as I do the default Sitefinity classification on the public side. Please see this example: http://www.apexalternativestrategies.com/education
More specifically, I'd like to be able to add one (or more) of these new 'secure categories' to each of my secure blog posts as I create the blog post using the default Sitefinity 'Create a post' feature.
My First Question to #1: How do I do this? If it's by creating a custom field in the blog post, where can I read more on how to do this?
And then, I would like to drop my new 'secure categories' classification onto my secure blog post page and have it work exactly as the public blog post page classification "filter" does on the example link I sent.
My Second Question to #1: What's the best way to do this? Should I create a new custom user control? If so, where can I get the code of the Sitefinity default classification user control so that I can modify it accordingly?
You said #2: As for the public side, you can drop the
Categories widget and show only the classification you want.
My Response to #2: This is exactly what I had already done, as you see in the example link I sent. :)
THANKS AGAIN!
Hi Ivan,
Hi Brian,
Please excuse us for the prolonged response, but we have been considering the priorities of this feature. The scenario you talk about is dependent on a couple of features that we currently lack. We have scheduled the following functionality for Sitefinity 5.1:
Hello, just curious as to when these items will be implemented. It mentions 5.1 but I don't see the option in the Sitefinity selectors to choose custom taxonomies yet. Is it now planned for 5.2?
Thanks
Hello, just curious as to when these items will be implemented. It mentions 5.1 but I don't see the option in the Sitefinity selectors to choose custom taxonomies yet. Is it now planned for 5.2?
Thanks
I also need to filter the archive control to specific blogs.
I am trying the custom control method as indicated by Ivan but have some questions.
Do we need to set LayoutTemplateName?
Also, in the sample code it says to blog posts for on the blog we need. That means not using the GetArchieveItems() functions anymore?
Then it says to bind the repeater control, but in the context of a custom control where is this repeater control and how do we reference it? The default layout will have a repeater already yes?
Am I missing something else?
Thanks ahead of time,
Eugene
Hello Eugene,
You can set to use the default template of the control in your code by calling the base property for the layouttemplate path ( if you want to use the default one ). However, if you want to customize the template as well you can get the template for the archive control from the SDK.
For your convenience I have created a sample control in which we add another Repeater to the ItemTemplate of the repeater, which displays the dates in the Archive widget. The second repeater lists all news items, depending on their publishing date. You can further modify the initial logic to change the content type and filter it further.
You can find the template, attached below. To map it in Sitefinity, go to Administration -> Settings -> Advanced -> Controls -> ViewMap and map the template the following way:
HostType: Telerik.Sitefinity.Web.UI.PublicControls.ArchiveControl
LayoutTemplatePath: PathToTheTemplate
Greetings,
Victor Velev
the Telerik team