Blog post as the page title

Posted by Community Admin on 03-Aug-2018 00:24

Blog post as the page title

All Replies

Posted by Community Admin on 10-May-2011 00:00

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)

Posted by Community Admin on 10-May-2011 00:00

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

Posted by Community Admin on 23-May-2011 00:00

Can we get a sample on how to do this? I'm having the same problem.

Posted by Community Admin on 23-May-2011 00:00

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

Posted by Community Admin on 24-May-2011 00:00

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

Posted by Community Admin on 24-May-2011 00:00

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

Posted by Community Admin on 24-May-2011 00:00

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


Posted by Community Admin on 24-May-2011 00:00

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)

Posted by Community Admin on 13-Jun-2011 00:00

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

This thread is closed