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:
List of recent blog entries for a given author.
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.
- In the third row of the second column, locate the Fields area. Click the + icon to add a field.
- Scroll down to Defaults: Add fields, below the settings table.
- In the Groups drop-down menu, select Node.
- Scroll down the list, select the Node: Title field, and click Add.
- 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.
- 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.
- In the second row of the third column, locate the Filters area. Click the + icon to add a filter.
- As before, scroll down to the Defaults: Add filters section, select Node from the Groups select box.
- 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.
- Now, by scrolling down to Live preview, you’ll see that the list only shows blog entries.
- We need to add an additional filter by clicking the + icon in the Filters section in the third column second row.
- Change Groups to Node and select Node: Published. Click Add.
- Under the Published selection, choose Yes and click Update.
- To handle sorting, locate the Sort criteria area, just above filters, and click the + icon there.
- Under Groups, again select Node. From the list of options, check Node: Post date and click Add.
- 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.
- Don’t forget to click Save!
A few more things to do before we create the block.
Creating The Block
- 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.
- 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.
- 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
- 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.
- Next, navigate to the blocks interface and configure the ‘My Recent Posts’ block.
- 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.
- 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?