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

Forums / Developing with Sitefinity / Figuring out Blog Post's ID from URL?

Figuring out Blog Post's ID from URL?

4 posts, 0 answered
  1. Victor
    Victor avatar
    44 posts
    Registered:
    10 Mar 2009
    27 May 2009
    Link to this post
    If displaying a Blog Post using a BlogPosts control on a page, is there a way to find out the Blog Post's ID from another control in the same page?

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    27 May 2009
    Link to this post
    Hi Victor,

    You can override BlogPosts control and get the content. ID

    Here is a sample below:

    using Telerik.Blogs.WebControls;  
    using System.Web.UI;  
    using Telerik.Cms.Engine;  
     
    /// <summary>     
    /// Custom implementation of BlogPosts     
    /// </summary>     
    public class CustomBlogPosts : BlogPosts  
    {  
        public override System.Type LocalizationAssemblyInfo  
        {  
            get 
            {  
                return typeof(BlogPosts);  
            }  
            set 
            {  
                base.LocalizationAssemblyInfo = value;  
            }  
        }  
        public override System.Type AssemblyInfo  
        {  
            get 
            {  
                return typeof(BlogPosts);  
            }  
            set 
            {  
                base.AssemblyInfo = value;  
            }  
        }   
        protected override void SetItemMetadata(Control itemContainer, IContent contentItem)  
        {  
            base.SetItemMetadata(itemContainer, contentItem);  
            LiteralControl literal = new LiteralControl();  
            literal.Text = contentItem.ID.ToString();  
            Controls.Add(literal);  
        }  
     

    If you want to show the IContent item Id on a separat control you can add the following logic in SetItemMetadata

    ITextControl otherControl = (ITextControl)itemContainer.FindControl("otherControl");  
    otherControl.Text = contentItem.ID.ToString(); 

    Where the otherControl is ITextControl that you have declared in the mapped template -ListPageDetails

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Victor
    Victor avatar
    44 posts
    Registered:
    10 Mar 2009
    28 May 2009
    Link to this post
    Can you please provide an example on how to make a BlogPosts control to use this class?

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    28 May 2009
    Link to this post
    Hello Victor,

    The built in BlogPosts control does not provide this functionallity out of the box. In this case you should use the custom control instead of the built in.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered