How To Create News Items in Drupal – Part 2

By | November 21, 2009

This is a continuation of the previous post that explained how to create a custom content type called News, and show News items using the Views module.

Creating A News Page with a Monthly News Archive Block

This post explains how to create a page showing just the News content type, how to link that page to the Primary menu, and how to show a block with a list of archived News items. It assumes you’ve already followed the steps in the previous post.

We accomplish all these tasks using the Views contributed module.

  • First, we use the Views module to create a page view to show most recent 10 news items on the page, as follows:
    • Login as site admin again
    • Go to Administer/Site building/Views.
    • Click Add to create a new View
    • View name: News_page , View description: Page showing recent news, View tag: News, View type: Node. Click Next.
    • Select ‘page’ in dropdown box, click ‘Add Display’. This is what creates a whole page, instead of a block, for example.
    • We want the user to be able to page back and forth through each set of 10 news items, so in the first column, click on ‘no’ next to ‘Use pager’ . Scroll down to the radio buttons for this option and click on ‘full pager’.
    • Next, we’ll repeat a lot of the steps we took for creating a block view – selecting the fields for the view, and the filter to choose only published News content:
      • 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.
      • Cick 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.
    • Let’s place this page on the Primary Menu.  This is the menu that (generally) appears at the top of your page, depending on your active Drupal theme.
      • Scroll down until you see the heading Page Settings in the first column.
      • Click on None (next to Path), and type: news . This is appended to the rest of your site’s url to make the full path for this page.  We will also refer to this name when we create our News Archive block.
      • The next option lets you link the page to a menu item:
      • Click on ‘No Menu’ (next to Menu)
      • Scroll down and click on Normal menu entry. A set of input controls appears to the right of this option. Proceed…
      • Type the title for this menu entry. I chose ‘News’ because I like short menu item text, but feel free to choose whatever you want- perhaps, Latest News.
      • Type a description. This appears when a user hovers over the menu item. It might appear somewhere else, too, I’m not sure.
      • Click on the dropdown box under the word ‘Menu:’
      • Select Primary Menu.  That’s it!
    • Finally, click the Save button (just above the words ‘Live Preview’.)

Create The News Archive Block

Ok – the next step is to create a block of Archived news articles – much like the standard Archive block that comes with Drupal. The only difference is that block includes all content types, while we want to include just our news content type. So this is really easy- we clone the existing Archive view that comes with the Views module and just add a filter to include only news content. Here are the steps in detail:

  • Go to Administer/Site building/views again.
  • Look for the existing view called Monthly Archive (it has a path of archive) – it’s the first one in the list in my install of Drupal. Click on the Clone link on the right.
  • Change the view name from archive to newsarchive, and change the view description similarly.
  • Click the next button to continue on to configure the block view.
  • Add the filter for news content only:
    • Click on the + sign next to Filters. Scroll down to see the list of available filter fields, find the Node: type field, and select it.
    • Scroll down to configure the Node type and select the news content type.
  • You can click the Live Preview button now, and you should see something like November 2009 (9) – at least that’s what I see, because that’s the only month I have any news items published in. If you haven’t written any news content yet, then nothing will show here.
  • Before we exit this page, there is, as Columbo would say, just one more thing.  You may have noticed that the Archive list we cloned has 3 vertical tabs on the left – Default, Page and Block.  In the previous steps we were changing the default settings, which essentially ripples them through to both the Page and Block settings. Personally, I intensely dislike this interface. It is quite confusing, because different options appear depending on which tab is active, and it’s not self-evident which tab is active. Anyway, we are going to make a minor change to the block view, so click on the block tab .
  • Scroll down until you see Block settings. If you do not see this heading then you did not click on the block tab in the previous step, so try again!
  • Click on the text next to Admin, and type ‘News Archive List’ . This is text appears when we are placing blocks on our pages, and if we don’t change it we will have two blocks with the same title – the one we cloned from, and this one – which makes it a pain to know which one we want to place somewhere.
  • Save your work – click the Update button, followed by the Save button below it.

Place the News Archive Block on The News Page

You may want to place your News Archive block on every page, but just for the sake of this tutorial, let’s place it only on the news page.

  • Go to Administer/Site Building/Blocks
  • Find your News Archive List block. It should be in the list with the heading Disabled, the last list on the page. Click on the Dropdown box next to it, and select the area on the page you want it to appear. The names of the areas will depend on the active theme you are using. There may be one called ‘right sidebar,’ which would be appropriate. If not, choose some other area.
  • Scroll to the bottom of the page and click Save Blocks  (IMPORTANT!!! – click Save Blocks before doing the next step – otherwise you may lose your ‘change’).
  • Ok – now you have to find your block in the lists on the page, because it has moved from the ‘disabled’ list to whatever area title you chose. Once you find it, click on the Configure link.
  • Scroll down to Show Block on Specific Pages, click the  ‘Show on only the listed pages’ radio button, then type news in the text area below. (news- not News, not ‘news’, not <news>).  If you recall, this is the node name of our news page, which we specified when we created the News page view (above).
  • Save your work.

Ok – we are done.If you  go to my Drupal sandbox site, you’ll see the News menu item at the top. Click on it and you’ll see some bogus news items, along with the News Archive List in a block on the right hand side. Notice that this block only appears on the news page, as per our specs.

Whew- this is a lot of text to explain something reasonably simple. Maybe next time I’ll make a youtube video instead.

35 thoughts on “How To Create News Items in Drupal – Part 2

  1. Maryann

    This was SOOO helpful!! Thanks so much for your help! Now what if I want the news list on the news page to show more than just the title of the news item? I’d like it to display maybe the first ten lines of the news item, then have a link that says “read more”. Is this possible with views?

  2. fbloggs Post author

    Yes- edit your view and select the field called Teaser. When you create News content, if you are using a WYSIWIG editor, you will see a button to insert a line break for a teaser. All the text before the break is considered part of the content’s teaser and will appear in your list.

  3. ade

    ive added 2 sets of news – can you think of any reason why i’m getting the 2 entries without links to their page and underneath the same 2 entries but with links

  4. fbloggs Post author

    Hard to say without seeing your code, but one quick thought I have- did you set your News content to ‘promote to front page’ by mistake? This will cause it to show up on the first page regardless of your block module settings. However, if they are both showing up in the same block module, I’d check your view and make sure you don’t have both a default and block view for the same content.

  5. azad

    Thanks a lot for all your hard work.
    what about translating the “News page” & the menu ( I have two languages Greek(default) & English )

  6. Arseny

    That was really amazing tutorial, your step-by-step explanation helps me lot! Continue doing this please 🙂

  7. ohad

    Thank you so much! This has been a great tutorial and very easy to follow!

  8. weblord

    Thanks, Sir fbloggs!!! This is the drupal features I was looking for. I just launched my first drupal website and trying to learn its features. Your comprehensive tutorial did helped me a lot understanding the use of “View” which is a very powerful tool to building a drupal website. Keep up the good work and more power to you and this website which I bookmarked. God bless you and your team! – Sheena

  9. Andy Welch

    Nice one mate, that was a good tutorial. Even though it’s a simple thing, it’s good to walk through the details.

  10. EamonnC

    Hi
    Thanks very much for this. Very helpful.

    The news items are only visible to Admin user. Any idea why this is?

    Thanks again
    EamonnC

  11. Erik

    Great tutorial! Thanks!
    But somehow, I can’t get the News to be unfolded on the news page. It shows up as the following:

    04.04.2010 – 00:11
    News4
    04.04.2010 – 00:11
    News3
    04.04.2010 – 00:10
    News2
    04.04.2010 – 00:09
    News1

    I do have content in them. What am I doing wrong?

  12. Pingback: How To Create News Items and a News List in Drupal

  13. Greg

    Hi,

    Great tut for a newbie like me. I only have one question, when I try and create the page to hold the most recent items, I’m warned that there is no path for this page and I subsequently don’t have any news items previewed even though I have created them.
    What path do I need to look for to add to this new View?
    Thanks again

  14. Tejas

    Hi,

    Thanks for tutorial.
    I want to show some summary content and read more link on News_page view.

    Please tell me the steps for it.

    Thanks,
    Tejas

  15. Tejas

    Also, I want to archived news by yearly not monthly.

    How to do that?

    Tejas

  16. yatin

    Hi, Need to display like Thank so what i have to do ?
    2010
    -jan
    -feb
    ….
    -dec
    2009
    2008
    2007

  17. Bruce

    Hi I have been slack and have just started getting into the content type thing and have news pages that are currently content types of “Page” is there an easy way for me to migrate the historical “Pages” to show up in the News “Views” I have attempted to create new “News” pages and they are using the current date information as the published dates.

    Thanks
    Bruce

  18. Dave

    A very useful walk through. Very often the tutorials for the more advanced modules assume advanced skills. As a relative newcomer I was able to follow this through and quickly implement what I needed. Thanks for taking the time to put this together.

  19. Kevin

    This tutorial is perfect, thank you for it!

    Just have one question : how did you apply specific styles for the news block? Is it possible to use a separate sytle sheet, or simply the CSS class name attribute of the block?

  20. Pingback: How To Create News Items and a News List in Drupal « Duongmv's Blog

  21. sekhar

    hi

    iam facing problem in controling the news items in archive how to control news is a problem. so many news showing in archive i have to control the number of news so help in this matter.

  22. Jones

    i’m not able to find “Scroll down until you see the heading Page Settings in the first column.”
    Can it be caused by my default theme ?

  23. fbloggs Post author

    I’m guessing you’ve already figured this out, but it looks like you need to click the Page box (instead of the Defaults box), just above the ‘Add display’ button. Clicking there will show you the Page settings box.

  24. Jones

    Thank you,
    Nice tutorial, very useful.
    Hope you will keep making these.
    Good luck

  25. Mubarak

    Three years down the line and still an excellent write up! Helped me in introduction to Views!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.