4

I have started my very first Craft project (coming from EE) - so, apologies if this is a to simple question.

On the homepage I want to display the latest news entry - and short excerpts from a few older ones. No other type of entries on the page.

Question: Should the section type of the homepage be a "channel" then, or a "single"? Or is there a something completely different way to do this?

7

Hi Magnus and welcome to Craft.

Your homepage should ideally be a Single. As the Craft site says these are one-off pages that have no special requirements or hierarchy.

You would then create a Channel called News (or Blog, whatever you require) and here you would have entries for each news article on your site.

Once you have everything set up, outputting the latest news article on your homepage is a very simple process:

{% set latestNews = craft.entries.section('news').limit(1) %}

{% if latestNews|length %}

    {% for article in latestNews %}
        <p>{{ article.title }}</p>
    {% endfor %}

{% endif %}

This code would sit in your index.twig template and grabs the 1st entry in the News section. Simple!

  • Great! A clear answer that even I understand – Magnus von Bromsen Feb 25 '15 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.