This is a migrated thread and some comments may be shown as answers.

Building custom sitemap

1 Answer 38 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gerrit
Top achievements
Rank 2
Gerrit asked on 18 Nov 2010, 06:42 AM
Hi guys,

I'm trying to build a custom sitemap but having some difficulties.
The sitemap used to work, but now I have pages that require a user to be logged-in first.

If I use the SiteMap.RootNode and the loop through all the children I dont see the "protected" pages.
So then I used the CmsManager.GetPages() which returns all the pages and thats all good, BUT I need the sitemap to display as it displays in the CMS, in that order.

Now it seems like the "Ordinal" value only applies for a group and the pages in the group or something, I have found a thread where it will sort the pages with the ordinal but the menu is still messed-up and not in the order as it is in the cms.

Can anyone help me on how to sort the items so that they will display as in the admin area?

Here is the code I'm using but does not seem to do exactly what I want( I have just added some custom code that will check if a user may see the page, and only then add it to the List ) :


internal class CmsPageComarer : IComparer<ICmsPage>
    {
        #region IComparer<ICmsPage> Members
 
        public int Compare( ICmsPage x, ICmsPage y )
        {
            return x.Ordinal.CompareTo( y.Ordinal );
        }
        #endregion
    }


private List<ICmsPage> GetSource()
        {
            CmsManager manager = new CmsManager();
            IList pages = manager.GetPages();
 
            List<ICmsPage> source = new List<ICmsPage>();
 
            foreach( ICmsPage page in pages )
            {
                string lang = "en";
                if( Request.Url.ToString().ToLower().Contains( "/af/" ) ) lang = "af";
                int langCode = 0;
 
                if( lang.Equals( "en" ) ) langCode = 127;
                if( lang.Equals( "af" ) ) langCode = 54;
 
                if( IsPageVisibleToUser( page ) && page.Navigable && page.LangID == langCode )
                {
                    //show in menu
                    source.Add( page );
                }
            }
 
            CmsPageComarer comparer = new CmsPageComarer();
            source.Sort( comparer );
 
            return source;
        }


internal class CmsPageComarer : IComparer<ICmsPage>
{
#region IComparer<ICmsPage> Members

public int Compare( ICmsPage x, ICmsPage y )
{
return x.Ordinal.CompareTo( y.Ordinal );
}
#endregion



private List<ICmsPage> GetSource()
{
CmsManager manager = new CmsManager();
IList pages = manager.GetPages();

List<ICmsPage> source = new List<ICmsPage>();

foreach( ICmsPage page in pages )
{
string lang = "en";
if( Request.Url.ToString().ToLower().Contains( "/af/" ) ) lang = "af";
int langCode = 0;

if( lang.Equals( "en" ) ) langCode = 127;
if( lang.Equals( "af" ) ) langCode = 54;

if( IsPageVisibleToUser( page ) && page.Navigable && page.LangID == langCode )
{
//show in menu
source.Add( page );
}
}

CmsPageComarer comparer = new CmsPageComarer();
source.Sort( comparer );

return source;

1 Answer, 1 is accepted

Sort by
0
Ivan Dimitrov
Telerik team
answered on 18 Nov 2010, 12:40 PM
Hello Gerrit,

You can take a look at this post that shows how to build the SiteMap There is a helper method GetPages(Guid parentId).

Kind regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Gerrit
Top achievements
Rank 2
Answers by
Ivan Dimitrov
Telerik team
Share this question
or