If you are using Drupal CMS for your website and you are displaying recent blog post items in a block anywhere in your website. You will see that it shows 10 recent blog posts always. I was trying to make it to list only 5 recent items but I didn’t get any clue how to do that.
After googling for few hours I got some solutions which I am sharing below.
Method 1 (Change in code under blog.module)
Usually Inside a blog.module there is one MySQL query which limits the query from 0,10 and we need to find that line and change it to 5 or whatever digit you want.
blog.module file is located at /modules/blog/blog.module , now open this file and find the lines where
$result = db_query_range(db_rewrite_sql(… SQL statement),0,10);
Then change digit 10 to 5 or any number that you wanted to show in a block list
Note: I am using Drupal 6.20 It may differ to another Drupal version thought but concept will be more or less same. I tested it and it is working fine for me.
But changing in code (hard coded) is not the right solution. Moreover, all website admins, owners are not technical person. Drupal should provide some admin setting under blog type to change the range.
Method 2 (Using Views Module)
I am using Drupal 6.20 although 6.24 is available (latest Drupal 6.x version). To use views features, we need to first install Drupal module called “views” from http://drupal.org/project/views
Once installed , you can see views settings at administer->site building->views
Then click on Add and add new views name with all the details that is being asked in that form and then click on next. Figure shows the format after clicking on add
Now you can see view type, title, description etc as shown in the image after clicking next
Now click on add (+ icon ) button and add under filters, sort criteria, fields etc to show the fully working block for blog list
Filters:
node published: yes
node type: blog entry
sort criteria
post date: desc
fields:
(whatever you wish to display)
node title: (link this field to its node)
By default it will list 10 under basic settings:
items to display: 10 change it to 5 or your desired number under Basic Settings->user pager
In the dropdown box click on add block display then save and you are done! You can see this view in your views list
Now go to Administer->Site building->Blocks
You will see Views: views name (ex: recent blog post) under disable tab. Choose option to display it anywhere in website like header or footer or sidebar etc then click on save button and you can see the recent blog posts of your desired count items.
Hope it will help and will work for you.