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

Forums / Designing with Sitefinity / Pass blog post category

Pass blog post category

5 posts, 0 answered
  1. harlowhair
    harlowhair avatar
    12 posts
    Registered:
    21 Nov 2006
    29 Oct 2009
    Link to this post
    Hi there,

    I have a blogposts control set up to display a list of blogs in a summary, and then when one is clicked it goes to a specially prepared page which displays the single blogpost - this works very well.

    What I also have on this page is a content view control that displays a list of content from a category however I would like this to be automatic.  I have set the content view to look for a querystring param called cat with the category name and this also works when I enter it manually but what I would like to do is for the blogpost category to automatically be appended to the querystring so this all happens automatically

    Is this possible?

    Thanks
    Rob
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 Oct 2009
    Link to this post
    Hello harlowhair,

    Here is a sample code that illustrates how to append the category of an item as a QueryString.

    public class CustomBlogPosts : BlogPosts
    {
        public CustomBlogPosts()
        {
        }
     
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageMaster.ascx";
            }
        }
     
     
        public override string SingleItemTemplatePath
        {
            get
            {
                return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageDetail.ascx";
            }
        }
     
        protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetItemMetadata(itemContainer, contentItem);
     
            HyperLink title = (HyperLink)itemContainer.FindControl("fullContent1");
            string itemCategory = (string)contentItem.GetMetaData("Category");
            if (title != null && !string.IsNullOrEmpty(itemCategory))
            {
                
                title.NavigateUrl = title.NavigateUrl + "?category=" + itemCategory;
            }
        }
     
    }

    Then you need to pass the value from the QueryString to your control and filter it.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. harlowhair
    harlowhair avatar
    12 posts
    Registered:
    21 Nov 2006
    30 Oct 2009
    Link to this post
    Thanks Ivan,

    Might seem a stupid question but where do I put this code?  I have tried creating a user control and using this in the code behind however when trying to us the control I get the following error:

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

    Source Error:

    Line 6:  using Telerik.Blogs.WebControls;
    Line 7:  
    Line 8: public partial class PennywiseBlogPosts : BlogPostsLine 9:  {
    Line 10:     public PennywiseBlogPosts()


    I have also tried just creating as a class and adding to an app_code folder however then do not know how to get the control onto a page?

    Thanks,
    Rob
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 Oct 2009
    Link to this post
    Hello harlowhair,

    This is a custom control that should be added to your App_Code folder or compiled. In .NET you cannot override classes from user controls. After you add the control in your App_Code folder you need to register it in your web.config file as shown below:

    <toolboxControls>

    <add name="CustomBlogPosts" section="Custom" type="CustomBlogPosts, App_Code" />

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. harlowhair
    harlowhair avatar
    12 posts
    Registered:
    21 Nov 2006
    30 Oct 2009
    Link to this post
    Ah - it was the web.config section that I was missing.  That works perfectly, thanks for your help!
Register for webinar
5 posts, 0 answered