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

Forums / Developing with Sitefinity / Change Search Result title

Change Search Result title

7 posts, 0 answered
  1. NEX
    NEX avatar
    25 posts
    Registered:
    14 Aug 2007
    19 Aug 2009
    Link to this post
    How can we change the title of the Search Result control list to show the page names instead of the site name?
  2. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    19 Aug 2009
    Link to this post
    Hello Alfred Pena,

    Thank you for using our services.

    I suppose that you are using the PageIndex. Usually for the PageIndex, the Search Results control will display the title of a page as title for each result in the result set.

    You want the name of the page to be used instead.

    Here is how to accomplish this:
    1. Copy the attached file in the App_Code folder of your web site.
    2. Open and edit the file located at ~[your site]/Sitefinity/cmsentrypoint.aspx and modify it so it look like this:
    <%@ Page Inherits="Telerik.Cms.Web.CustomInternalPage, App_Code"  
       MasterPageFile="~/Sitefinity/Dummy.master" %> 
    3. Start indexing all of your PageIndexes again.

    I hope this helps you.

    Regards,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  3. NEX
    NEX avatar
    25 posts
    Registered:
    14 Aug 2007
    20 Aug 2009
    Link to this post
    Didn't work...

    Take a look at the site:
    http://seasite.nexsoftware.com/App_Master/SiteSearchResult.aspx?IndexCatalogue=TotalSite&SearchQuery=security

    See, all the Titles have Seasite.  We want to change that to the Page Menu Name.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 Aug 2009
    Link to this post
    Hi Alfred Pena,

    As I see it all your pages have the same title "SeaSite", so the control returns this page title in the repeater for each item. Please modify the Tile of each page or apply the code below to Sitefinity/ControlTemplates/Search/SearchResult.ascx.

    <%@ Control Language="C#" %> 
     
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %> 
    <%@ Register Assembly="Telerik.Search" Namespace="Telerik.Search.WebControls.Admin" 
        TagPrefix="sfSrc" %> 
    <%@ Import Namespace="Telerik.Cms.Web" %> 
    <script runat="server"
         
        public string GetPageName(string url) 
        { 
            SiteMapNode sNode = SiteMap.Provider.FindSiteMapNode(url); 
            return ((CmsSiteMapNode)sNode).CmsPage.Name; 
        } 
     
    </script> 
    <sfWeb:CssFileLink ID="CssFileLink1" FileName="~/Sitefinity/ControlTemplates/Search/searchCommonLayout.css" Media="screen" runat="server" /> 
     
    <h2><asp:Literal ID="ResultsStats" runat="server">Found {0} pages for "{1}" </asp:Literal></h2
     
     
     
    <asp:Repeater ID="rptResults" runat="server"
        <HeaderTemplate> 
            <dl class="searchResults"
        </HeaderTemplate> 
        
        <ItemTemplate> 
            
            <dt><strong><href='<%#DataBinder.Eval(Container.DataItem, "Url")%>'><%# GetPageName(DataBinder.Eval(Container.DataItem, "Url").ToString()) %></a></strong></dt>   
            <dd><%#DataBinder.Eval(Container.DataItem, "Snippet")%></dd
            <dd><em><href='<%#DataBinder.Eval(Container.DataItem, "Url")%>'><%#DataBinder.Eval(Container.DataItem, "Url")%></a
                        </em></dd>  
        </ItemTemplate> 
        <FooterTemplate> 
            </dl> 
        </FooterTemplate> 
    </asp:Repeater> 
     
        ... 
          .... 
            ..... 


    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.
  5. TriXia
    TriXia avatar
    1 posts
    Registered:
    21 Aug 2009
    21 Aug 2009
    Link to this post
    Hello,

    What would be the best way to do the following: page titles of format "SiteName - PageName" but on search results title to show only "PageName". Is it possible to use Menu label (which contains "PageName") as a title for search results instead of Title?

    Thanks,
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    23 Aug 2009
    Link to this post
    Hi TriXia,

    You can just return CmsPage.MenuName as below:

    return ((CmsSiteMapNode)sNode).CmsPage.MenuName; 

    Regards,
    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.
  7. James
    James avatar
    11 posts
    Registered:
    09 Jan 2008
    08 Apr 2011
    Link to this post
    I used the following code based off of this thread which fixed two problems for me (Object Not Related and No Title Showing up for News Items).

    public string GetPageName(string url, object DataItem)
        {
             
            SiteMapNode sNode = SiteMap.Provider.FindSiteMapNode(url);
            if (sNode != null)
            {
                if (((CmsSiteMapNode)sNode).CmsPage.Parent != null)
                {
                    return ((CmsSiteMapNode)sNode).CmsPage.Parent.Title + " - " + ((CmsSiteMapNode)sNode).CmsPage.Title;
                }
                else
                {
                    return ((CmsSiteMapNode)sNode).CmsPage.Title;
                }
            }
            else
            {
                if (DataItem is Telerik.Search.Engine.ResultItem)
                {
                   return ((Telerik.Search.Engine.ResultItem)DataItem).Title;
                }
      
            }
      
            return "";
        
      
      
      
      
    <dt><strong><a href='<%#DataBinder.Eval(Container.DataItem, "url")%>'><%# GetPageName(DataBinder.Eval(Container.DataItem, "url").ToString(), Container.DataItem) %></a></strong></dt>
Register for webinar
7 posts, 0 answered