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

Forums / General Discussions / Blog Widget URL

Blog Widget URL

3 posts, 0 answered
  1. Stephanie
    Stephanie avatar
    19 posts
    Registered:
    16 Mar 2011
    02 May 2011
    Link to this post
    Hi,

       I am having an issue with my blog widget linking to the correct page.  I have 3 different blogs set up in my project.  On the index page, I have a blog widget in the left side, displaying posts from all blogs.  When a specific blog title is clicked, the URL is incorrect and the full story displays in the wrong page.

    Ex)  Under my main navigation I have a Bloggers link, on that page within a content block I have a list of links to 3  blogger's pages.

    /bloggers/Name1
    /bloggers/Name2 ... etc.

    From the index page, when I click the title of the blog in the left side bar, I would like the URL to redirect to the specific bloggers page and show the posting that was clicked.

    Ex)  bloggers/Name2/Name2-blog/2011/05/02/blog-title   (first post listing)
           bloggers/Name2/Name1-blog/2011/05/02/blog-title   (second post listing)

    How can I have all posts displayed, but each linking to a different URL?

    Thank you,

    Steph
  2. Antoaneta
    Antoaneta avatar
    258 posts
    Registered:
    02 Nov 2015
    06 May 2011
    Link to this post
    Hi Stephanie,

    Thank you for contacting us.
    The case you describe is currently not supported byBlog post widget. You can select a page where posts to be displayed but this will apply to all blog posts. 

    I logged this as a feature request in our issue tracking system PITS where you can follow its progress. The ID is 5862. I have updated your Telerik points.

    As a workaround I would suggest to put every blog in a separate widget. Then you can select to display items only from a specific blog and also to specify where you want them to be opened.

    If you need more information or screenshots please, let me know.

    Regards,
    Antoaneta
    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. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    06 May 2011
    Link to this post
    I've been thinking about this and believe this is a great opportunity to make use of the Custom Fields feature of Sitefinity. By adding a "DetailsPage" custom field to the blog, you can internally associate a blog with a page.

    Of course by design the blogs are supposed to be detached so you can place the widgets anywhere and everywhere as well as being able to move the blog details page and other actions without breaking links or anything like that.

    However, if your site is pretty static, this can make for a good workaround. I implemented a proof of concept based on your problem and I think it works pretty well! I will put this into a blog post for the general community soon but for now here's a quick summary.

    First, add a custom field "DetailsPage" to the Blogs (that's at the BLOG level, NOT to blog POSTS). For each blog, specify the path to the details page.

    For example, I have a blog "Test Blog 1" and its detail page is http://mysite.com/blogs/blog-1. So in the properties page for the blog, I set the custom field DetailsPage to be /blogs/blog-1. Do the same for each blog/page pairing.

    Next, make a custom user control to display all of the blog posts combined. Here I'm just showing the title but you can modify it to show whatever fields you need. The GetUrl is a method I'll define in the code behind.

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BlogPostsList.ascx.cs" Inherits="SitefinityWebApp.Widgets.BlogPostsList" %>
      
    <asp:ListView ID="BlogPostsListView" runat="server">
        <ItemTemplate>
            <h3><a href="<%# GetUrl(Container.DataItem) %>"><%# Eval("Title") %></a></h3>
        </ItemTemplate>
    </asp:ListView>

    In the code behind I used the Fluent API to retrieve the posts as well as make a method to parse out the url when binding to the frontend control.

    protected void Page_Load(object sender, EventArgs e)
    {
        // this is the list of posts we'll bind to
        var posts = new List<BlogPost>();
        // initialize fluent API
        using (var fluent = App.WorkWith())
        {
            // get all blogs
            var blogs = fluent.Blogs().Get();
            foreach (var blog in blogs)
            {
                // add posts to the list
                foreach (var post in blog.BlogPosts.Where(p => p.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live))        
                    posts.Add(post);
              
            }
        }
        // bind posts to list view
        BlogPostsListView.DataSource = posts;
        BlogPostsListView.DataBind();
    }
    protected string GetUrl(object item)
    {
        // cast dataitem to post
        var post = item as BlogPost;
        if (post == null) return string.Empty;
        // get parent blog
        var blog = post.Parent;
        // create link from parent and blog details
        return string.Format("{0}/{1}/{2}/{3}", blog.GetValue("DetailsPage"), blog.UrlName, post.PublicationDate.ToString("yyyy/MM/dd"), post.UrlName);
    }

    I then installed the widget to the toolbox and dropped it onto the main /blogs page. It now shows the list of posts from all blogs in one list, and each post links to its individual blog page!

    This was an interesting task and I look forward to going into detail in a blog post soon. Thank you for the inspiration and I hope that you find this example helpful!

    let me know if you have any questions on this example, have a great weekend!
3 posts, 0 answered