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

Forums / General Discussions / Blog post as the page title

Blog post as the page title

9 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    10 May 2011
    Link to this post
    If I'm viewing a blog post, I'd like the title of the browser to be the title of the post...

    How can I get that to work?  Google seems to be indexing everything as "<Site> Blog" instead of something like "<Site> Blog <Post Title>" (or whatever)
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 May 2011
    Link to this post
    Hi Steve,

    One of the options here is using custom PageRouteHandler where you can get the PageData obeject you should set its HtmlTitle at runtime. Generally the Title is set though ObjectFactory and IoC, but the method cannot be overridden from there, so PageRouteHandler looks like more appropriate place.

    Greetings,
    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. adam
    adam avatar
    2 posts
    Registered:
    04 May 2011
    23 May 2011
    Link to this post
    Can we get a sample on how to do this? I'm having the same problem.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 May 2011
    Link to this post
    Hello adam,

    Create a custom class that inherits from PageRouteHandler and override ProcessSiteNode method which is virtual. There get the page data and set the HtmlTitle

                var siteMap = (SiteMapBase)node.Provider;
                var pageSiteNode = (PageSiteNode)node;
                var manager = PageManager.GetManager();
                var pnode = manager.GetPageNode(pageSiteNode.Id);
                pnode.Page.HtmlTitle = "test";

    Best wishes,
    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
  5. Matthew Tamm
    Matthew Tamm avatar
    4 posts
    Registered:
    26 Oct 2004
    24 May 2011
    Link to this post
    Unfortunately this does not work with a "Redirecting Page" as, in the example, pnode.Page is null ...I am sure this has to do with the Redirecting page design, consider the following:

    If my URL is /page1 that redirects to /page1/page2, then with a redirecting page, if I browse /page1, Sitefinity substitutes /page1/page2, but the title is not set, assume as ProcessSiteNode is never actually called for the /page1/page2.  A simple example using the code supplied previously should demonstrate this

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 May 2011
    Link to this post
    Hello Matthew ,

    ProcessSiteNode  is called when you open an item in a single mode.

    Greetings,
    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
  7. adam
    adam avatar
    2 posts
    Registered:
    04 May 2011
    24 May 2011
    Link to this post
    Is this the only solution?  Is there any other solution that doesn't involve creating custom classes and overriding methods?
    Someting like this? http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/blog-post-page-title.aspx


  8. Matthew Tamm
    Matthew Tamm avatar
    4 posts
    Registered:
    26 Oct 2004
    24 May 2011
    Link to this post
    It is amazing that this is not easier (not that doing the supplied example is all that hard) - it's just that it does not work in 100% of scenarios (redirect or group pages as a simple example)
  9. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    13 Jun 2011
    Link to this post
    This worked for me, getting the blog title during the itemdatabound event of the DetailsView and using PreRender to add to the page meta.
    1) Create a custom widget project, add your references and add a class that inherits from Telerik.Sitefinity.Modules.Blogs.Web.UI.Public.DetailPostView.

    namespace YourCompany.ModuleName
    {
        [ControlTemplateInfo("BlogResources", "BlogsDetailViewFriendlyName", "BlogsTitle")]
        public class BlogDetailsView : Telerik.Sitefinity.Modules.Blogs.Web.UI.Public.DetailPostView
        {
            private string strTitle = string.Empty;
            private string strDescription = string.Empty;
            private string strKeywords = string.Empty;
             
            public BlogDetailsView()
            {
            }
     
            public void DetailsView_ItemDataBound(object sender, RadListViewItemEventArgs e)
            {
                if (e.Item.ItemType == RadListViewItemType.DataItem || e.Item.ItemType == RadListViewItemType.AlternatingItem)
                {
                    RadListViewDataItem item = e.Item as RadListViewDataItem;
                    BlogPost bp = (BlogPost)item.DataItem;
                    if(bp.Title != null)
                        strTitle = bp.Title.ToString();
                    if (bp.Summary != null)
                        strDescription = bp.Summary.ToString();
                    TaxonomyManager tm = new TaxonomyManager();
     
                    var keywords = new List<string>();
                    var cats = (Telerik.OpenAccess.TrackedList<System.Guid>)bp.GetValue("Category");
                    if (cats.Count > 0)
                        foreach (Guid g in cats)
                        {
                            HierarchicalTaxon ht = (HierarchicalTaxon)tm.GetTaxon(g);
                            if (ht != null && !keywords.Contains(ht.Name.ToLowerInvariant()))
                                keywords.Add(ht.Name.ToLowerInvariant());
                        }
                    var tags = (Telerik.OpenAccess.TrackedList<System.Guid>)bp.GetValue("Tags");
                    if (tags.Count > 0)
                        foreach (Guid g in tags)
                        {
                            FlatTaxon ft = (FlatTaxon)tm.GetTaxon(g);
                            if (ft != null && !keywords.Contains(ft.Name.ToLowerInvariant()))
                                keywords.Add(ft.Name.ToLowerInvariant());
                        }
                    if (keywords.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string s in keywords)
                        {
                            sb.Append(s);
                            sb.Append(",");
                        }
                        strKeywords = sb.ToString();
                        if (!String.IsNullOrEmpty(strKeywords))
                            strKeywords = strKeywords.Substring(0, strKeywords.Length - 1);
                    }
                }
            }
     
            protected override void InitializeControls(GenericContainer container, IContentViewDefinition definition)
            {
                this.DetailsView.ItemDataBound += new EventHandler<RadListViewItemEventArgs>(this.DetailsView_ItemDataBound);
                base.InitializeControls(container, definition);
            }
     
            protected override void OnPreRender(EventArgs e)
            {
                if (string.IsNullOrEmpty(this.strTitle) == false)
                    this.Page.Title = strTitle + " - " + Page.Title;
                if (string.IsNullOrEmpty(this.strDescription) == false)
                    this.Page.MetaDescription = strDescription;
                if (string.IsNullOrEmpty(this.strKeywords) == false)
                    if (!String.IsNullOrEmpty(this.Page.MetaKeywords))
                        this.Page.MetaKeywords += "," + strKeywords;
                    else
                        this.Page.MetaKeywords = strKeywords;
                     
                base.OnPreRender(e);
            }
        }
    }

    2) Add a reference to this project in SitefinityWebApp

    3) Then in

    Administation > Settings > Advanced > Blogs > Controls > BlogPostsFrontend > Views > DetailsBlogPostsFrontend

    change the ViewType to your new view : YourCompany.ModuleName.BlogDetailsView

    Ryan
9 posts, 0 answered