Need to Pull Data from Multiple PageLists

Vote:
 

Currently, we have a section of our site that is structured as follows:

Archives (PageList)

2013(PageList)

News Story (News Article)

News Story (News Article)

2012 (PageList)

News Story (News Article)

 

The issue is I need to pull the news stories despite the year and display them on our home page. When I set "Archives" as the data source, it only pulls "2013" and "2012". Is there a way to skip over the secondary PageLists so I can display the news stories.

I've tried to filter using the following:

private void HomeNewsPageList_Filter(object sender, FilterEventArgs e)
        {
            var pages = e.Pages;
            for (int i = pages.Count - 1; i > -1; i--)
            {
                if (pages[i].PageName as string == PageBase.Translate("/news/archivesheading") || pages[i].PageTypeName as string != "News Article" || pages[i].PageName.Length == 4)
                {
                    pages.RemoveAt(i);
                }
            }
        }

 

This seems to be a start in the right direction to exclude the secondary PageList, but I cannot display the respective children. Any suggestions?

 

Thanks in advance!

 

    

 

 

#69835
Apr 08, 2013 10:17
Vote:
 

You coud try to set the DataSource on your list in pageload instead of directly in the control. You need to fetch descendants, not only children.

This should work:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

List<PageReference> pageRefs = DataFactory.Instance.GetDescendents(LinkToArchivePage);

PageDataCollection filteredCollection = new PageDataCollection();

foreach (PageReference pageReference in pageRefs)
{
PageData page = DataFactory.Instance.GetPage(pageReference);
if (page.PageTypeName == "News Article")
filteredCollection.Add(page);

}

yourPageList.DataSource = filteredCollection;

}

 

 

#69892
Apr 09, 2013 11:33
Vote:
 

I didn't see this sooner. Thank you for the prompt reply. I'm now subscribed to email notifications on this thread so I won't miss anything again. The code builds, but now I realize I haven't handled filtering the results by the currently selected language. Any thoughts? After researching, it seems maybe I should have gone down the "FindPagesWithCriteria" approach, but I'm wondering if there's a way to modify what you've provided without having to start over. I tried the code below and it almost works, but now is pulling in the page lists as well (2013,2012 from the first post) well.

Thanks!

    


protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!IsPostBack) { this.LanguageString = (System.Globalization.CultureInfo.CurrentCulture).ToString(); HomePageNewsList.PageLinkProperty = PageLinkProperty; if (MaxCountProperty != null && CurrentPage[MaxCountProperty] != null) { HomePageNewsList.MaxCount = (int)CurrentPage[MaxCountProperty]; } // Hide the whole control if the list is empty //this.Visible = HomePageNewsList.DataCount > 0; PageReference NewsPullPage = CurrentPage.Property["MainListRoot"].Value as PageReference; IList<PageReference> pageRefs = DataFactory.Instance.GetDescendents(NewsPullPage); PageDataCollection filteredCollection = new PageDataCollection(); foreach (PageReference pageReference in pageRefs) { PageData page = DataFactory.Instance.GetPage(pageReference); if (page.PageTypeName == "News Article" && page.LanguageBranch == LanguageString && page.PageName.Length != 4) filteredCollection.Add(page); } HomePageNewsList.DataSource = filteredCollection; HomePageNewsList.DataBind(); } }

    

#70309
Edited, Apr 17, 2013 4:17
Vote:
 

I think it is this line that make the 2012, 2013 pages appear in your list:

HomePageNewsList.PageLinkProperty = PageLinkProperty;

You kind of set the datasource twice I think. I do not think it is possible for the 2012 and 2013 pages to be added with the filter (the if-sentence) in place.

 

Try to remove the codeline mentioned and I think it should work. 

#70311
Apr 17, 2013 7:49
Vote:
 

Yep, of course that was the problem. Thank you so much!!

#70362
Apr 17, 2013 20:54
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.