How To Produce News List and a News Items in Drupal

29 July 2013

San Francisco: Drupal does not come with an out-of-the-box news content type. You could use a story or a blog entry, but these are not an exact fit for what I required.  Favorably, it’s pretty easy to create your own ‘News’ content type. You most likely have your own idea of what a ‘news item’ should be, and how it must exhibit.

Here are the features needed for news items:

Requirements

  • News items to be their own ‘content type’ so I can create user roles just for posting news items.
  • Latest 5 news items to show in a block on the first page.
  • Separate ‘news’ page that lists all news items, most recent first, with paging (eg. show 10 at a time).
  • ‘news’ page should be a Primary menu item
  • List to show date of item and title of item, with the title being a link to the full article
  • News items to support ‘teasers’
  • Have an Archive block on the News page to show an archive of news items by month

Summary of Process

Here’s an outline of how you do it, followed by detailed instructions.

  • Install Views contributed module (if you haven’t already done so).
  • Install Advanced Help module (this provides a great example of using Views to create a block or page that presents lists of information)
  • Create a content type of ‘news’
  • Check the options to add, change or delete own news items for the appropriate users or roles.
  • Create a ‘block’ view to display news items
  • Place the block somewhere on the first page
  • Create a ‘page’ view to display news items.  You choose which Primary menu item you want to use for this page when you create the view.
  • Create an ‘archive’ block view to display archives by cloning the provided Archive view and changing it
  • Place the archive block somewhere on your news page.

Details for Creating the News Block

In this segment of the post I take you through every step in detail.

1. Install Views and Advanced Help modules.

Views are one of two very popular contributed (non-core) modules. CCK (Custom Content Kit) is the other one- it lets you create your own data values or content types. Views let you display lists of information from the Drupal database. It’s essentially a user-driven SQL statement generator, along with some list formatting options. Advanced Help is useful because it gives you detailed examples on using Views. One of those uses content type of ‘Story’, which is really not much different than the ‘news’ content type we are using here. Here are the URLs for each of these modules:

  • Views
  • Advanced Help

In this example, you are suggested to employ Views 2 for Drupal 6.x.

2. Create Content type of ‘news’.

  • Login as Site admin
  • Go to Administer/Content Management/Content Types, click Add.
  • Name: News, Type: news (I use all lower-case for the type), Description: News items.
  • Workflow settings: Check ‘Published’ and ‘Promoted to front page’. I also enabled Attachments, but you may not want to do that. Make your choice for comments, too. You probably don’t want people commenting on your news items – “hey – that was really boring!” – in which case, disable comments.
  • Save the content type.

3. Set up a User who can create, change or delete News items. First we’ll create a new role, specifically for just working with news items:

  • Go to Administer/User Management/Roles
  • Click on Add Role. Call it Reporter (you can always delete this later if you really don’t want it)
  • Click on Edit Permissions         
  • Scroll down the list of permissions until you get to ‘Node Module’. Check ‘Create news content’, ‘edit own news content’ and ‘delete own news content’ then click ‘Save permissions.
  • Create a user with a role of reporter: Go to Administer/Users and click on ‘Add User’. Type a Username, unique e-mail address (if you are like me, you have many alias email addresses pointing to the same account- almost a must for testing anything with Drupal or Joomla), password, and check the role of ‘reporter’.

4. Add some News!

  • Logout of Drupal
  • Login with the User just created (role of reporter)  
  • Click on the ‘Create content’ link and create some news items.

5. Create a block view to show most recent 5 news items in a block.

  • Login as site admin again
  • Go to Administer/Site building/Views.
  • Click Add to create a new View
  • View name: News_list , View description: block listing recent news, View tag: News, View type: Node. Click Next.
  • Select ‘block’ in dropdown box, click ‘Add Display’.
  • Click on ’10′ next to ‘Items to display’ and change it to 5.
  • Click on the ‘+’ sign next to Fields. Scroll down and select Node: Post date and Node: Title, then click the Add button . The next steps take you through more options for each of these fields.
  • Remove the label of ‘Post date’ (clear the text). This prevents the words ‘Post date’ showing next to the date. Click ‘Update default display’. You should now see an interface asking you to configure the field ‘Node:Title’.
  • Remove the label of ‘Title’ (clear the text). Check the box ‘Output this field as a link’ , scroll down and check ‘Link this field to its node’. This makes the News item’s Title a clickable link that links to the full article (node). Click ‘Update Default display’.
  • You should see a ‘Live preview of all content you’ve created. Let’s filter it by ‘news’ only.
  • Click the ‘+’ sign next to Filters. Scroll down and check Node: Published and Node: Type. These options let us choose to display only Published content (Node: Published = Y), and only news (Node: Type = ‘news’). Then click Add.
  • Select ‘Yes’ for Published items, click Update, then select ‘Is one of’ and check ‘News’, then click Update.
  • Now let’s sort the news items by most recent first (descending order). Click on the ‘+’ sign next to Sort criteria.
  • Check Node: Post date, click Add.               
  • Select Descending, click Update.
  • Finally, click the Save button (just above the words ‘Live Preview’.)

6. Add Block to First Page

  • Depending on your active theme, you may want to add your news block to the left or right side of the page. I’m (currently) using Acquia Marina, which supports a right-hand column, so that’s where I’ll place my block:
  • Go to Administer/Site Building/Blocks
  • Scroll down to the list of inactive blocks and find the one named ‘News_list’. This is what we created when we built our view in the previous steps. Click on the dropdown box and select ‘Sidebar last’ (or maybe ‘Sidebar right’ or ‘Sidebar left’ – depending on your active theme).
  • Click the ‘Save blocks’ button at the bottom of the page.
  • The list of blocks will be refreshed. The news_list block now appears under the ‘sidebar last’ heading. Click on the ‘configure’ link.
  • Type a ‘block title’ of Latest News
  • Scroll down to ‘Page specific visibility settings’ and click on ‘Show on only the listed pages’ and type <front> in the text box. This ensures that our block of listed news items only appears on the front page, on the right side of the page.

Read more: Drupal Web Development

 

Why Fortune Innovations?

  • Save your project cost up to 40%
  • Hire remote web developers & web designers
  • San Francisco based project management
  • 50 plus strong off shore development team based in Bangalore, India
  • Innovative team members with Web 2.0 expertise
  • Quality driven delivery model
  • Detailed time sheets & daily reporting
  • WordPress Development in San Francisco
  • Drupal Development in San Francisco
  • Joomla Development in San Francisco
  • eCommerce Magento San Francisco
  • Web Development San Francisco
  • Web Design San Francisco
  • jQuery development San Francisco
  • Zend framework development San Francisco
  • Airline IBE GDS Integration Navitaire San Francisco
  • Airline IBE GDS Integration Aamadeus San Francisco