Forum OpenACS Q&A: Re: Including latest blog on front page

Collapse
Posted by Vinod Kurup on
The default is to show 30 days worth of posts. I hacked mine to show a certain number of posts, based on a parameter. If the parameter is set to 0, then it's ignored and 30 days of posts are shown. It's currently PG-only cuz it uses the LIMIT clause, but here it is in case you want it as a base to start from:
Index: lars-blogger.info
===================================================================
RCS file: /cvsroot/openacs-4/packages/lars-blogger/lars-blogger.info,v
retrieving revision 1.8.2.10
diff -u -b -B -r1.8.2.10 lars-blogger.info
--- lars-blogger.info	1 Jul 2003 13:28:25 -0000	1.8.2.10
+++ lars-blogger.info	10 Jul 2003 02:09:27 -0000
@@ -24,6 +24,7 @@
         <callbacks>
         </callbacks>
         <parameters>
+            <parameter datatype="number"  min_n_values="1"  max_n_values="1"  name="NumPostsOnFrontPage"  default="0" description="How many posts do you want on your front page? Enter 0 to show the last 30 days of posts."/>
             <parameter datatype="number"  min_n_values="1"  max_n_values="1"  name="package_rss_feed_p"  default="1" description="Should we build an RSS feed for this instance." section_name="rss"/>
             <parameter datatype="number"  min_n_values="1"  max_n_values="1"  name="user_rss_feed_p"  default="0" description="Should we build an RSS feed for each user." section_name="rss"/>
             <parameter datatype="string"  min_n_values="1"  max_n_values="1"  name="rss_file_name"  default="rss.xml" description="What name should we advertise the RSS feed under, relative to the blog mount point. Leave blank if no RSS feed." section_name="rss"/>
Index: www/blog-postgresql.xql
===================================================================
RCS file: /cvsroot/openacs-4/packages/lars-blogger/www/blog-postgresql.xql,v
retrieving revision 1.3.2.4
diff -u -b -B -r1.3.2.4 blog-postgresql.xql
--- www/blog-postgresql.xql	13 Jun 2003 09:15:01 -0000	1.3.2.4
+++ www/blog-postgresql.xql	10 Jul 2003 02:09:27 -0000
@@ -42,6 +42,7 @@
 		    and    draft_p = 'f'
 		    and    deleted_p = 'f'
 		    order  by entry_date desc, posted_date desc
+		    $limit_clause
         </querytext>
     </fullquery>
 
Index: www/blog.tcl
===================================================================
RCS file: /cvsroot/openacs-4/packages/lars-blogger/www/blog.tcl,v
retrieving revision 1.8.2.6
diff -u -b -B -r1.8.2.6 blog.tcl
--- www/blog.tcl	1 Jul 2003 13:28:26 -0000	1.8.2.6
+++ www/blog.tcl	10 Jul 2003 02:09:27 -0000
@@ -26,14 +26,30 @@
 
 if { ![info exists type] } {
     set type "current"
+
+    # does user want 30 days of posts or a certain number of posts
+    set num_posts [parameter::get \
+		       -package_id $package_id \
+		       -parameter NumPostsOnFrontPage \
+		       -default 0]
+
+    if {![string equal $num_posts 0]} {
+        set type "number_posts"
+    }
 }
 
 switch -exact $type {
     archive {
         set date_clause "[db_map date_clause_archive]"
+        set limit_clause ""
+    }
+    number_posts {
+        set date_clause "1=1"
+        set limit_clause "limit $num_posts"
     }
     default {
         set date_clause "[db_map date_clause_default]"
+        set limit_clause ""
     }
 }