#3: added pagination links at bottom of the blog page
This commit is contained in:
@@ -66,7 +66,7 @@ feature -- HTTP Methods
|
|||||||
n: CMS_NODE
|
n: CMS_NODE
|
||||||
lnk: CMS_LOCAL_LINK
|
lnk: CMS_LOCAL_LINK
|
||||||
hdate: HTTP_DATE
|
hdate: HTTP_DATE
|
||||||
page_number:NATURAL_16
|
page_number, tmp:NATURAL_16
|
||||||
do
|
do
|
||||||
-- At the moment the template is hardcoded, but we can
|
-- At the moment the template is hardcoded, but we can
|
||||||
-- get them from the configuration file and load them into
|
-- get them from the configuration file and load them into
|
||||||
@@ -81,7 +81,7 @@ feature -- HTTP Methods
|
|||||||
page_number := page_number_path_parameter (req)
|
page_number := page_number_path_parameter (req)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Ensure that page is never 0 (happens if /blogs/ is routed)
|
-- Ensure that page is never 0 (happens if /blogs/ is routed and then "" interpreted as 0)
|
||||||
if page_number = 0 then page_number := 1 end
|
if page_number = 0 then page_number := 1 end
|
||||||
|
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||||
@@ -96,10 +96,10 @@ feature -- HTTP Methods
|
|||||||
end
|
end
|
||||||
s.append ("</h2>")
|
s.append ("</h2>")
|
||||||
|
|
||||||
|
-- Get the posts from the current page (given by page number and entries per page)
|
||||||
if attached node_api.blogs_order_created_desc_limited (entries_per_page, (page_number-1) * entries_per_page) as lst then
|
if attached node_api.blogs_order_created_desc_limited (entries_per_page, (page_number-1) * entries_per_page) as lst then
|
||||||
-- Filter out blog entries from all nodes
|
|
||||||
--if n.content_type.is_equal ("blog") then
|
-- List all posts of the blog
|
||||||
s.append ("<ul class=%"cms-blog-nodes%">%N")
|
s.append ("<ul class=%"cms-blog-nodes%">%N")
|
||||||
across
|
across
|
||||||
lst as ic
|
lst as ic
|
||||||
@@ -108,23 +108,23 @@ feature -- HTTP Methods
|
|||||||
lnk := node_api.node_link (n)
|
lnk := node_api.node_link (n)
|
||||||
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
|
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
|
||||||
|
|
||||||
-- Post date (creation)
|
-- Output the date of creation of the post
|
||||||
if attached n.creation_date as l_modified then
|
if attached n.creation_date as l_modified then
|
||||||
create hdate.make_from_date_time (l_modified)
|
create hdate.make_from_date_time (l_modified)
|
||||||
s.append (hdate.yyyy_mmm_dd_string)
|
s.append (hdate.yyyy_mmm_dd_string)
|
||||||
s.append (" ")
|
s.append (" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Author
|
-- Output the author of the post
|
||||||
if attached n.author as l_author then
|
if attached n.author as l_author then
|
||||||
s.append ("by ")
|
s.append ("by ")
|
||||||
s.append (l_author.name)
|
s.append (l_author.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Title with link
|
-- Output the title of the post as a link (to the detail page)
|
||||||
s.append (l_page.link (lnk.title, lnk.location, Void))
|
s.append (l_page.link (lnk.title, lnk.location, Void))
|
||||||
|
|
||||||
-- Summary
|
-- Output the summary of the post and a more link to the detail page
|
||||||
if attached n.summary as l_summary then
|
if attached n.summary as l_summary then
|
||||||
s.append ("<p class=%"blog_list_summary%">")
|
s.append ("<p class=%"blog_list_summary%">")
|
||||||
if attached api.format (n.format) as f then
|
if attached api.format (n.format) as f then
|
||||||
@@ -139,13 +139,32 @@ feature -- HTTP Methods
|
|||||||
|
|
||||||
s.append ("</li>%N")
|
s.append ("</li>%N")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- End of post list
|
||||||
s.append ("</ul>%N")
|
s.append ("</ul>%N")
|
||||||
|
|
||||||
-- Show the pagination if there are more than one page
|
-- Pagination
|
||||||
if more_than_one_page then
|
s.append ("<div class=%"pagination%">")
|
||||||
s.append ("<ul class=%"pagination%">")
|
|
||||||
|
|
||||||
|
-- If exist older posts show link to next page
|
||||||
|
if page_number < pages then
|
||||||
|
tmp := page_number + 1
|
||||||
|
s.append (" <a class=%"older_posts%" href=%"/blogs/" + tmp.out + "%"><< Older Posts</a> ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Delmiter
|
||||||
|
if page_number < pages AND page_number > 1 then
|
||||||
|
s.append (" | ")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- If exist newer posts show link to previous page
|
||||||
|
if page_number > 1 then
|
||||||
|
tmp := page_number -1
|
||||||
|
s.append (" <a class=%"newer_posts%" href=%"/blogs/" + tmp.out + "%">Newer Posts >></a> ")
|
||||||
|
end
|
||||||
|
|
||||||
|
s.append ("</div>")
|
||||||
|
|
||||||
--end
|
--end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user