2016-04-06 74 views
0

我們需要顯示一個顯示X帖子的博客文章頁面 - 第一篇文章顯示爲標題,其餘爲2列。頁面底部有一個顯示更多按鈕,它使用ajax獲取下一頁的文章,並在底部添加它們。 是否可以爲後續頁面獲取X + 1項目?如何爲Orchard的第一頁設置不同的頁面大小CMS

任何提示,即使在代碼中也是受歡迎的,因爲我們使用源碼版本的果園安裝。

+0

你從Ajax調用哪個動作?通常,分頁操作有一個「PagerParameters」 - 參數。正常的尋呼機只是添加一個像「?pageSize = 50」這樣的queryString,你可以利用它。這應該不夠嗎? – Xceno

+0

@Xceno我不認爲Orchard中的博客文章將頁面大小作爲參數傳遞,因爲每個博客都有自己的頁面大小屬性。 – fotisgpap

+0

BlogController上的實際Item-Action採用上述參數。 (烏節1.10的源代碼) 你是正確的,因爲pageSize被博客設置中指定的頁面覆蓋,但你可以很容易地改變。 – Xceno

回答

1

因此,在混淆上述評論之前,這是我提出的解決方案。

我認爲有關於更改控制器動作,我想澄清(我希望我現在能正確理解的一切)有輕微的誤解:

Orchard.Blogs | BlogController |項目操作

public ActionResult Item(int blogId, PagerParameters pagerParameters) { 
    // This is all original code 
    Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); 

    var blogPart = _blogService.Get(blogId, VersionOptions.Published).As<BlogPart>(); 
    if (blogPart == null) 
     return HttpNotFound(); 

    if (!_services.Authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent, blogPart, T("Cannot view content"))) { 
     return new HttpUnauthorizedResult(); 
    } 

    // This is the actual change: 
    // Use the pagerParameters provided, otherwise fall back to the blog settings 
    pager.PageSize = pagerParameters.PageSize.HasValue ? pager.PageSize : blogPart.PostsPerPage; 

    // This is all original code again 
    _feedManager.Register(blogPart, _services.ContentManager.GetItemMetadata(blogPart).DisplayText); 
    var blogPosts = _blogPostService.Get(blogPart, pager.GetStartIndex(), pager.PageSize) // Your new page size will be used 
     .Select(b => _services.ContentManager.BuildDisplay(b, "Summary")); 
    dynamic blog = _services.ContentManager.BuildDisplay(blogPart); 

    var list = Shape.List(); 
    list.AddRange(blogPosts); 
    blog.Content.Add(Shape.Parts_Blogs_BlogPost_List(ContentItems: list), "5"); 

    var totalItemCount = _blogPostService.PostCount(blogPart); 
    blog.Content.Add(Shape.Pager(pager).TotalItemCount(totalItemCount), "Content:after"); 

    return new ShapeResult(this, blog); 
} 

所以變化是很微妙的,但這樣一來我就配置博客默認pageSize的7項以後每Ajax的要求我提供與希望的「pageSize的」 - 參數尺寸。

+0

完美工作!非常感謝@Xceno! – fotisgpap

相關問題