+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Blog rotator anyone?

Blog rotator anyone?

5 posts, 0 answered
  1. Jake Dacillo
    Jake Dacillo avatar
    12 posts
    Registered:
    13 Oct 2009
    07 Dec 2011
    Link to this post
    Has anyone had any luck with creating a control to rotate blog entries? We have a requirement to rotate our 3 most recent blog entries, only displaying one at a time, just the title, summary, and a link to read more....I am very new to Sitefinity. Any help would be much appreciated. Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Dec 2011
    Link to this post
    Hello Jake,

    You can use ContentManager and its method GetContent to get all blog posts you want. Then you need to bind a RadRotator control with this datasource.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jake Dacillo
    Jake Dacillo avatar
    12 posts
    Registered:
    13 Oct 2009
    12 Dec 2011
    Link to this post
    Thank you for the reply. Do you by chance have a link to any instructions or guidelines on how to implement the Rad controls?
  4. Jake Dacillo
    Jake Dacillo avatar
    12 posts
    Registered:
    13 Oct 2009
    12 Dec 2011
    Link to this post
    Here is what I have so far as I am waiting for the Rad Controls to install. I have a page I made with the .ascx file:

    <%

    @ Control Language="C#" AutoEventWireup="true" CodeFile="blogrotator.ascx.cs" Inherits="UserControls_BlogRotator_blogrotator" %>

     

    <%

    @ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %>

     

    <

     

    asp:Repeater runat="server" ID="listOfAllBlogs">

     

     

    <ItemTemplate>

     

     

    <asp:Label runat="server" ID="PostTitle" Text='<%# Eval("Title") %>'></asp:Label><br />

     

     

    <asp:Label runat="server" ID="Content" Text='<%# Eval("Content") %>'></asp:Label>

     

     

    </ItemTemplate>

     

    </

     

    asp:Repeater>

     



    and the code behind:

    using

     

    System;

     

    using

     

    System.Collections.Generic;

     

    using

     

    System.Linq;

     

    using

     

    System.Web;

     

    using

     

    System.Web.UI;

     

    using

     

    System.Web.UI.WebControls;

     

     

     

     

     

    public

     

    partial class UserControls_BlogRotator_blogrotator : System.Web.UI.UserControl

     

    {

     

    protected void Page_Load(object sender, EventArgs e)

     

    {

     

    // create new instance of BlogManager

     

    Telerik.Blogs.

    BlogManager blogManager = new Telerik.Blogs.BlogManager();

     

     

    // get all blogs

     

     

    var listOfAllBlogs = blogManager.GetBlogs();

     

     

    if (listOfAllBlogs.Count > 0)

     

    {

     

    foreach (Telerik.Blogs.IBlog blogItem in listOfAllBlogs)

     

    Response.Write(blogItem.Name +

    "<br />");

     

    }

    }

    }


    Am I on the right track?
  5. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    02 Dec 2016
    15 Dec 2011
    Link to this post
    Hello Jake Dacillo,

    Implementing a BlogRotator should not be much different than the ImageRotator sample we've included in our Documentation - you generally need to add a RadRotator to your ascx and specify what you want to be displayed in its ItemTemplate. Then in the code-behind you can get the range of blogs/blog posts that you want your Rotator do display, and subscribe to its ItemDataBound event where you have to configure the declared controls in the rotator's ItemTemplate. Here's a short example demonstrating how you can rotate all posts under a particular blog:
    <table>
       <tr>
           <td id="BlogRotator_table">
              <div class="BlogRotator_NavigationLeft" style="float:left">
                 <asp:Image ImageUrl="~/Controls/LeftNavBttn.png" ID="img_left" AlternateText="left" runat="server" Style="cursor: hand; float: left;"/> 
               </div>
     
               <div  style="float:left">
                  <telerik:RadRotator runat="server" ID="BlogRotator" EnableRandomOrder="true"
                               Width="535" Height="303" ItemWidth="535" ItemHeight="303" ScrollDirection="Left"
                                       RotatorType="Buttons" EnableEmbeddedSkins="false" ScrollDuration="500" FrameDuration="2000">
                   <ItemTemplate>
                       <asp:Literal ID="TitleLink" runat="server" />
                       <asp:Literal ID="Literal2" Text="Posted By" runat="server" />
                       <asp:Literal runat="server" ID="AuthorName"></asp:Literal>
                       <asp:Literal runat="server" ID="PostDate"></asp:Literal>
                       <asp:Literal runat="server" ID="PostContent"></asp:Literal>
                   </ItemTemplate>
                   <ControlButtons LeftButtonID="img_left" RightButtonID="img_right" />
                   </telerik:RadRotator>
               </div>
     
               <div class="BlogRotator_NavigationRight" style="float:left">
                   <asp:Image ImageUrl="~/Controls/RightNavBttn.png" ID="img_right" AlternateText="right" runat="server" Style="cursor: hand; float: right;" />
               </div>
           </td>
       </tr>
       </table>

    private string Blog = "MyBlog";
     
            public string BlogTitle
            {
                get { return Blog; }
                set { Blog = value; }
            }
             
            protected void Page_Load(object sender, EventArgs e)
            {
                    BlogRotator.DataSource = getImages();
                    BlogRotator.ItemDataBound += new RadRotatorEventHandler(BlogRotator_ItemDataBound);
                    BlogRotator.DataBind();
            }
     
            private List<BlogPost> getImages()
            {
                var results = App.WorkWith().BlogPosts().Publihed().Where(bP => bP.Parent.Title == BlogTitle).Get().ToList();
                return results;
            }
     
            protected void BlogRotator_ItemDataBound(object sender, RadRotatorEventArgs e)
            {
                var item = e.Item.DataItem as BlogPost;
                if (item != null)
                {
                    var titleLink = e.Item.FindControl("TitleLink") as Literal;
                    titleLink.Text = item.Title;
     
                    var authorName = e.Item.FindControl("AuthorName") as Literal;
                    var name = UserProfilesHelper.GetUserDisplayName(item.Owner);
                    authorName.Text = name;
     
                    var postDate = e.Item.FindControl("PostDate") as Literal;
                    postDate.Text = item.PublicationDate.ToLocal().ToString();
     
                    var postContent = e.Item.FindControl("PostContent") as Literal;
                    postContent.Text = item.Content;
                }
            }

    Please do not hesitate to let us know if you have any additional questions, we'll be glad to help.

    All the best,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
5 posts, 0 answered