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

Collapse
Posted by James Harris on
Is there an easy way of including the latest blog on the front page of an OpenACS site?  I know there is a way of including all the blogs (though I can't find the code at this instant) and I think this is what Lars does on his home page.

What I would prefer to do is simply display the latest entry along with standard text that gets displayed every time.

Collapse
Posted by Lars Pind on
Nope, not out of the box.

If you look at the documentation, you'll find instructions on how to include the whole blog. Perhaps you can make simple modifications to suit your needs?

http://cvs.openacs.org/cvs/openacs-4/packages/lars-blogger/www/doc/index.html

(click 'download')

/Lars

Collapse
Posted by James Harris on
Thanks Lars, I'll try to have a look at it over the weekend.

Another question I have is whether it is possible to control the number of blog entries that show up on the blog home page.  It appears that they are all displayed which can obviously lead to long pages.  It would be cool to have a parameter which controls the maximum number displayed on the home page.

Collapse
Posted by Jarkko Laine on
James,

They are not all displayed. Can't remember the exact amount (or time span) of entries shown, though. I guess both the blogger home page and includable snippet use same proc to get the entries, so it shouldn't be too hard to put there a parameter for maximum number of entries shown.

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 ""
     }
 }
 
Collapse
Posted by James Harris on
I'm using PG so it will be a good place to start from.  I may well be able to use that to limit the total number displayed and then include them all on the front page using Lars' example.

Thanks.

Collapse
Posted by Lars Pind on
Damn. I accidentally parameterized this.

I started with Vinod's patch, but then generalized it a bit.

I added 3 parameters: Min number of entries, max number of entries, and date limit.

The idea is this: Max and Date work in conjunction, to mean "at most x days or y posts, whichever comes first".

Min entries only works if you the date limit also set, to say "well, but if the number of entries within the last x days is less than y (min entries), show y entries".

It's on the tip of oacs-4-6 branch, and will go out in 4.6.4 later this summer.

/Lars

Collapse
Posted by James Harris on
That sounds exactly what I'd like so I think I'll wait.  I've just included the entire blog on my home page at this stage.
Collapse
Posted by Jon Griffin on
It is very easy to emulate limit in Oracle.

Look at my paginate post and you can get code that does this, without changing any querys. Maybe it should be made into a proc or plsql function. I will look into this later.