Archives Widget
Hello There, I am using archives widget for my blog posts in a page I am getting the results of Month and year in a list. I want those results needs to be display like drop down navigation.
Hi Nagesh,
You can extend the ArchiveControl widget, however notice that you won't be able to remove the default repeater from the control template to replace it by a DrowDownList since the ArchiveControl will expect the repeater.
An easy approach consists on just adding the DropDownList to the template and setting Visible=false for the repeater as you can see in this short video. Then populate the DropDownList with the repeater data.
The control template could be like this:
<%@ Control Language="C#" %><%@ Register TagPrefix="sitefinity" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" %><script type="text/javascript"> function redirect(url) this.window.location.href = url; </script><asp:PlaceHolder ID="plhTitle" runat="server" Visible="false"> <h2 class="sfarchiveTitle"> <asp:Literal ID="titleLabel" runat="server"/> </h2></asp:PlaceHolder><asp:Repeater Visible="false" ID="rptArchive" runat="server"> <HeaderTemplate> <ul class="sfarchiveList"> </HeaderTemplate> <ItemTemplate> <li class="sfarchiveListItem"> <sitefinity:SitefinityHyperLink ID="linkArchive" runat="server" CssClass="selectCommand sfarchiveLink"></sitefinity:SitefinityHyperLink> </li> </ItemTemplate> <FooterTemplate> </ul> </FooterTemplate></asp:Repeater> <div class="sflanguagesDropDownList"> <asp:DropDownList runat="server" ID="newsSel" CssClass="sflanguagesDropDown" onchange="redirect(this.value)"></asp:DropDownList> </div>using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Sitefinity.Modules.GenericContent.Archive;using Telerik.Sitefinity.Web.UI.PublicControls;namespace SitefinityWebApp.MyControls public class CustomArchiveWidget : ArchiveControl public override string LayoutTemplatePath get return "~/MyControls/CustomArchiveTemplate.ascx"; public DropDownList NewsSelector get return this.Container.GetControl<DropDownList>("NewsSel", false); protected override void ArchiveRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) base.ArchiveRepeater_ItemDataBound(sender, e); ArchiveItem archive = e.Item.DataItem as ArchiveItem; if (archive != null) NewsSelector.Items.Add(new ListItem(ResolveDisplayText(archive.Date), ResolveUrl(archive.Date))); if (IsDateInRange(archive.Date)) NewsSelector.Items[NewsSelector.Items.Count - 1].Selected = true; Thank you so much Junior Dominguez
Dear Junior
I have used the same code what u have suggested but how can I use this for BlogPosts.
When I placed it in a blog page i am getting just dropdown there is no results of the blog post dates.
Please help me on this
Hi Nagesh,
Set the widget property ContentType to Telerik.Sitefinity.Blogs.Model.BlogPost as described in our documentation.
http://www.sitefinity.com/documentation/documentationarticles/user-guide/widgets/navigation-widgets-group/configuring-the-archive-widget
Kind Regards,
Junior Dominguez
Telerik
Dear Junior
First of all thank u so much for your continuous support.
I can not able to get the content type field in edit archives widget option.
I used the same code and process and registered widget in tools.
Am i doing any wrong?
Hi Nagesh,
Notice that for blog posts you need to use the BlogPosts widget. Following the same procedure described in the previous message will work on your end. I recorded this other video for reference.
Best wishes,
Junior Dominguez
Telerik
Thank u so much Junior
I appreciate your help.