Quickly create a "latest blogs" list with the REPORTS module

Location: BlogsAll BlogsDNN Development    
Posted by: mamlin 5/20/2009 3:39 AM

A common request is for a "latest blog entries" list for the core BLOG module.  We'll see how to quickly make such a list for free using the core REPORTS module...
 
 
Latest Blog Entries
The current version of the core BLOG module lacks a "Latest Blog Entries" list.  Such a list is useful on a homepage (such as the Blog entries list found on this site's homepage) on in a sidebar.  Fortunately we can easily create such a list using the core REPORTS module.  There are a few considerations we'll want to consider, but first let's jump right to making that list...
 
Step 1 -- Add the REPORTS module to a test page
When using the REPORTS module, always try your new queries out on a test page before using the module on a "production" page.  If your test query goes horribly, horribly wrong you will then have the option of simply deleting the test page using the ADMIN -> TABS module.  If you'd placed the test module on a "production" page then you'll have a little more trouble removing the module without altering the rest of the page.  Trying things out on a test page (or test website) is just good practice.
 
So...add the module to a test page.
 
Step 2 -- Set the SQL query field in the module's SETTINGS
Go into the REPORTS module SETTINGS.  Under the "REPORT SETTINGS" section, add the following to the QUERY field and then click "Update":
 
  select top 5 Title 
  as [Latest Blog Entries]
  from blog_entries
  where Published = 1
  order by AddedDate desc 

 
Done.  You now have a list of the five latest blog entry titles.

Well, actually.....we're not done.  The list is nice but we want a clickable list so users can click the title and be taken to the blog entry.  Also, this query returns the latest blog entries from all portals in our DNN instance.  We want to insure that we only include the Blog entries for the current portal.
 
EDIT 5/21/2009  Dario Rossa of the DNN Blog project team has pointed out that we should consider whether a blog is marked "public" or not.  That is, we should include entries only for blogs intended for public view.  This is a point I'd overlooked in my initial post.  I've added the appropriate clause recommended by Dario to the SQL below.  Thanks, Dario!

We need a better (and more complex) query.  Go back into the module SETTINGS and replace your original query with this one:

  select top 5
    '<a href="'+PermaLink+'">'+ble.Title+'</a>' 
  as [Latest Blog Entries]
  from blog_entries ble
  inner join blog_blogs bb on bb.Blogid = ble.Blogid
  where ble.Published = 1
  and bb.Portalid = @portalID
  and bb.public = 1
  order by ble.AddedDate desc
 
 
Ahhh.....that's better.  We now have a clickable list thanks to the handy "PermaLink" URL the Blog module has already created for us.  Notice that the REPORTS module allows us to insert HTML right into our query results -- very handy if you only need a small bit of HTML for a task such as we needed for our clickable links.
 
 
Other Considerations
Ok, now that the fun part is over it's time to put on our "serious" faces.  What do we have?  A list of the five most recently-published blog entries.  Simple, right?
 
Well.....perhaps you have your site set up to allow individual users to create their own blogs.  In such a case you may not want to list the latest blog entries from just any user, but only from a select group of "preferred bloggers".  You'd need to extend the query to filter out any entries for users who are not part of a custom-added "preferred blogger" user role (or user group).
 
Another variation would be that you only want to include the latest blog entries under a particular parent blog.  Or perhaps you'd like a list of each of the three latest blog entries from EACH blog on your site.  Your need may be even more specialized than a simple "latest entries" list -- for instance, we previously explored one means of providing a clickable list of the "most-commented" blog entries.
 
All this is to say that one "blog entires" query certainly does not fit all needs.  Thankfully the REPORTS module is often capable of delivering what we need as long as we're clever enough with our SQL to grab the required data.
 
 
Related Entries
Here's a list of other blog entries where we've quickly created an easy (and free) solution with a single SQL query (except for the "Tag Cloud" which also required a helper function):

 
Comments?

Permalink |  Trackback

Comments (2)   Add Comment
Re: Quickly create a "latest blogs" list with the REPORTS module    By Newman Joseph on 5/21/2009 7:01 AM
Its really nice. i got the result after a long time. Thanks for ur Help. keep rocking.

Re: Quickly create a "latest blogs" list with the REPORTS module    By Lewis Conner on 7/30/2009 1:23 PM
I'm no techie but I can follow instructions and I got a working module in a few minutes. However, I did receive an error message saying there was a syntax error near the term "public" so I simply deleted that line. Thanks for making these helpful tips available.


Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
You are here:  
 
>> Back to the top of the blog list...

 
        account   advanced   blog   click   cloud   code   content   create   data   different   events   example   feature   file   files   free   function   good   google   just   line   list   module   modules   need   option   page   pages   query   results   role   roles   script   search   select   settings   simple   site   skin   solution   step   tags   terms   time   user   users   value   version   want  
Minimize Google AJAX Search
 
Search ES:  
This is an example of a Google AJAX Search with asynchronous search execution for two searches.  See our blog series, 'Add Google AJAX Search to your DNN skin' for info and sample code.
 
     
Minimize Get the T-Shirt
 
Shirts by Eguana Solutions
(Be cool like us!)
 
     
Minimize Most-Commented Blogs
 
 
     

Minimize Looking for more info?
 

There are tons of helpful
posts from Eguana Solutions 
on the DotNetNuke.com forums.
  
 
Click HERE to see our posts.

 
     
Minimize Modules for Sale
 

Looking for Eguana's modules? 
We're still working on them!
  

Until ours are ready to dazzle and
amaze, you'll have to make do with
the thousands of modules already
available on SnowCovered.

 
     
Minimize Favorite Modules
 

There are many great DNN modules.
A few we highly recommend are:
 
Dynamic Registration
Total control over the user signup process.  Create custom forms, execute your own SQL, use the integrated payment processing features to assign user roles, validate USERNAMEs via AJAX and much more.  Very cool.
 
URL Master
Change to friendly URLs that really ARE friendly.  Add keywords into your page URLs for better SEO.  Create 301 redirects for individual pages.  Force visitors (and search bots) to a single domain (i.e., make everyone use the "www" version of your site's URL or vice versa).  One of the single best upgrades for any DNN site.
 
Document Exchange 5 (DMX5)
Drag-and-drop from Windows Explorer directly into the DMX file manager!  File versioning, file and folder moderation, extend user permissions down to the file level (for user groups and even for individual users).  Infinite file and file info presentation options via custom display templates.  Store files locally or remotely via UNC (i.e., can securely store files somewhere besides your web server).  Much more.
 
XMOD by DNNDev
Rock-solid form module for data collection.  From simple feedback / email forms to complex, multi-part tabbed forms.  XMOD is different from other form modules because XMOD does not create a new database table for every new form definition -- an important feature if you plan to create dozens or hundreds of forms over the life of your DNN instance!  Excellent support from the developer and an active community around this module.
 
If you desire your form module to create a new DB table for each new form definition, a great alternative to XMOD is the Dynamic Forms module from DataSprings.  Dynamic Forms offers direct DB access beyond that found in XMOD as well as an easy drag-and-drop form builder option to help you get up and running very quickly.

 
     

Login