E-book Preview - Front Page View And Block Placement
This is a short preview from my forthcoming e-book Building Your Blog With Drupal 7. There are two sections previewed here.
- Getting Your Blog Posts Onto The Front Page - I explain how to create a simple page, RSS feed and block using the new Views 3 interface.
- Arranging Sidebar Blocks - I explain how you can place the block you created in the previous section into the sidebar of your page.
Getting Your Blogs Posts Onto The Front Page
The next things you’re going to do are to set up a “view” (which is basically a list) for your blog posts and make that view the front page of your site. It’s true that there are simpler ways to do this, namely clicking the Promoted to front page checkbox in the add content window, but Views is so integral to Drupal that I think you should get started using it sooner rather than later.
To get started click on the Structure link in the admin menu, then select the Views link which should be the last one in the Structure window. At the very top of the next window you will see an Add new view link. When you click that link you should see a window that looks like the image below.
There are a lot of choices to make when adding a new view so I’ll make it easy for you and show you the choices I have made in the image below.
You’re free to change any of the details to suit your own needs. The most important thing to understand is that these choices will result in the following features.
- A list of blog posts with the newest blog post displayed at the top
- A dedicated page at yourblog.com/blog that shows ten teaser (or summary) posts that include the title, the beginning of the body field and a link to the full post
- A dedicated RSS feed that people can use to subscribe to the blog in an RSS reader
- A block that you can place in the sidebar that has links to the five most recent posts
Once you have filled in your choices click the Save and exit button to complete the creation of your feed. The screen will refresh and you’ll be looking at the new page you created at yourblog.com/blog. You should see the “Hello World” post you created and an orange RSS feed icon that links to the blog feed. Now that the view for your blog has been created the next thing you want to do is make that view the front page of your site.
Click on Configuration in the admin menu then select the Site information link. The second section from the top of the site information page is called “Front Page”. Change the “Default front page” field from “node” to “blog” or whatever path you gave to your blog post view. Click Save configuration then navigate to your site home page. The front page of your site should now look something like the image below.
Besides your blog posts the blocks to the left side of your posts are another important element of your site. The block you see on the top is the standard search block. I’ll have you leave that in place. The next blog down is the navigation block which we really don’t need since we have the administration bars at the top of the page. In the next section I will show you how to remove that block and add other blocks that you do need.
Arranging Sidebar Blocks
Click on Structure in the admin menu and then select the Blocks link which is the first link. You will see a table that looks like the one in the image below. Focus on the “Sidebar first” section of the table.
Click on the list box in the Navigation row and set the value to “-None-“. You’ll notice that Navigation disappears from the row. Scroll down to the very bottom of the page and drag the row called “blog_posts: Block” to the space below the Search form field. Then navigate to the bottom of the page and click the Save blocks button. Navigate to the home page and you will now see the Recent Posts block below the Search block.
If you like you can also add a Recent Comments block to the sidebar. The Drupal core comments module has created this block for you. Just go to the block administration window and drag “Recent Comments” to the appropriate position or select “Sidebar first” from the list box in the Recent Comments row. Keep in mind that those changes are not saved until you select the Save blocks button.
The final block that I’ll have you place for now is the block that will hold your tag (or category) “cloud”. In the Block administration window look for “Tags in Tags” and move that to Sidebar first then save your blocks. If you go to the home page it should now look something like the image below.
You’ll notice that the “Tags in Tags” block has a dotted line around it with a configuration icon in the upper right portion of the block. The ability to go to the edit views of blocks directly from the block itself is a nifty new feature in Drupal 7. You should see something like that when you put your cursor directly over the block and point to the configuration icon. For all blocks you have the option of editing the title, the access levels and even the pages that they appear on. Tags in Tags happens to be a block that has an additional configuration option. You can edit the number of tags that appear in the block.
If you click on the configure block link that appears when you mouse over the configuration icon you will be taken to the block edit window where, among other things, you can adjust the block title to something like “Topics” and also change the number of tags that will be displayed if you like. Remember to click the Save button at the bottom of the window. Once you do that you will be returned to the home page of your site.
One thing you may have noticed when looking at your block configuration is the fact that the User login block is placed in the Sidebar first section. If you don’t want anonymous users to see that blog you should remove it just like you removed the Navigation block. You can always reach the login page of your site by navigating to /user/login.
I hope that you enjoyed this short preview. I have most of the content in the e-book finished. Once the content is complete I will be working on perfecting the formatting and cleaning up errors that I find along the way. If you want to be among the first to know when the e-book is finished then I suggest that you do one of three things if you haven't already.
- Subscribe to posts via the main Learn By The Drop RSS feed.
- Follow @learnbythedrop on Twitter.
- Like the Learn By The Drop Facebook page.
Copyright 2011, Robert Safuto, Some Rights Reserved. Please visit Learn By The Drop to comment, subscribe or explore additional content not available via the RSS Feed.