Using Drupal 6 Views To Create Offset Recent Posts.

This past weekend I was searching for a way to take the recent posts block and have it display offset posts and limit it to 5 posts.

I found information on creating it by using php code inserted into a block, I was looking for something simpler.

The solution was to start leaning more about the Drupal Views module. So when in doubt it always pays to read the manual. In the Views tutorial there is a section titled “Create a block of author’s recent blog posts.”

Going through the tutorial will give you a greater understanding of the views module and its capabilities. I am already using drupal views with the bonus pack to display the 5 most recent posts on the front page of the site with no pagination.

I wanted a block to display an additional 5 more posts that where offset. The default Recent blog posts as we know shows 10 posts in descending order.

My goal was to have a new view of offset posts that display only on the front page. Then use the default “Recent blog posts” block on all other nodes.

Here are the modified steps I used from “Create a block of author’s recent blog posts” to arrive at this goal.

Creating the View

The first step is creating a view for our recent blog entries block. Because the block will show the titles of blog entries, this view is considered a “Node” type. Go to add new view, enter the following properties, and click Next:

View name
my_recent_blog_entries

View description
List of recent blog entries for a given author.

View tag
blog

View type
Node

Generating the list of blog entries

It will be much easier to see the view progress if we can see it doing something. In this section, we will create a basic view displaying blog entry titles.

  1. In the third row of the second column, locate the Fields area. Click the + icon to add a field.
  2. Scroll down to Defaults: Add fields, below the settings table.
  3. In the Groups drop-down menu, select Node.
  4. Scroll down the list, select the Node: Title field, and click Add.
  5. Now you will be presented with settings for the Node: Title field. Delete the label from the Label field, that way each individual node title is not prefixed with the word “Title.” Additionally, check the Link this field to its node box.
  6. When finished, click Update. If you scroll down to the Live Preview section, you should now see a list of several node titles; however both blog entries and other node types will be in the list. Let’s fix that.
  7. In the second row of the third column, locate the Filters area. Click the + icon to add a filter.
  8. As before, scroll down to the Defaults: Add filters section, select Node from the Groups select box.
  9. Scroll down and select the Node: Type field and click Add. In the settings page that appears, leave Operator as Is one of and select Blog entry under Node type. Click Update when finished.
  10. Now, by scrolling down to Live preview, you’ll see that the list only shows blog entries.
  11. A few more things to do before we create the block.

  12. We need to add an additional filter by clicking the + icon in the Filters section in the third column second row.
  13. Change Groups to Node and select Node: Published. Click Add.
  14. Under the Published selection, choose Yes and click Update.
  15. To handle sorting, locate the Sort criteria area, just above filters, and click the + icon there.
  16. Under Groups, again select Node. From the list of options, check Node: Post date and click Add.
  17. In the settings page, change Sort order to Descending. This will place the newer posts on top of the older ones. Click Update when finished.
  18. Don’t forget to click Save!

Creating The Block

  1. In the first column, under Defaults, there is a select box containing entries such as Page, Feed, and, Block! Select Block and click Add display.
  2. Click the Name “None” link under Basic settings and fill in a description for the block in the administrative interface, such as: ‘My Recent Posts.’ and click Update.
  3. Next we will put in the offset, make sure you are on the newly created block “My Recent Posts.” Under Basic settings you will see the link Items to display: 10. Click on the 10, scroll down. Here you will see the default value of 10. I set mine to 5 posts, then set the offset to 5. Click Override, then click update
  4. Save your work by clicking the Save button at the bottom of the Views interface. You should receive a message that the view has been saved.
  5. Next, navigate to the blocks interface and configure the ‘My Recent Posts’ block.
  6. I titled my block “More Recent Posts” I only want this block to display on the front page. In the Page specific visibility settings, select “Show on only the listed pages, and set it to “front” click Save Block.
  7. Next place it into your choice of left or right sidebar region and click Save blocks.

At first it seems like quite a bit of work but it’s well worth it. And it opens up the possiblities to do the same with “Story” content. With the views module in Drupal, what else can we do?

Comments on this entry are closed.

  • dereine Oct 1, 2009 @ 15:18

    We could export the view as code 🙂

    I think this would people help do the same thing 🙂

  • David Feb 7, 2010 @ 21:04

    Thanks for the quick and easy tutorial. Underscored what I already knew, and answered some questions. Thanks! Keep up the good work.

    David

    • Glenn Feb 7, 2010 @ 22:27

      Hi David,

      The wonderful thing about Drupal is there is always something new to learn. And seeing just how far the this CMS can be pushed.

  • Richard Feb 28, 2010 @ 19:06

    Glenn,
    I’m new to Drupal and was looking for an easy to understand tutorial on Views basics. Thanks for making yours simple to follow for a beginner like myself.

    Richard

    • Glenn Feb 28, 2010 @ 19:19

      Hi Richard,

      Glad you found it useful. Views is a powerful module, I wish I had more time to play with it myself.

      I have a project I’ll be working on soon, I’m waiting on Drupal 7 to come out and hope to document the process extensively.

  • Priya Jul 13, 2010 @ 8:04

    Hi Glenn,

    Perfect tutorial for views. I just started with Drupal recently. Your post is really helpful.
    Thanks

  • Kris Jan 18, 2011 @ 8:22

    Excellent. A perfect tutorial.

    Kris