Should I create a Single for the blog home page content (/blog) and then a Channel to hold the entries (/blog/{slug})?

The blog index page also needs to have non blog entries on, i.e. intro text describing what the blog is about.

  • Yes. :) At least, that's one way of doing it. – André Elvan Sep 5 '14 at 12:08
up vote 3 down vote accepted

A Channel called Blog as follows:

  • Entry URL Format: blog/{slug}
  • Entry Template: blog/_entry

In blog/_entry.html:

{% extends "_layout" %}
{% set title = "{{ entry.title }}" %}

{% block content %}
    <article>
        <h2><a href="{{ entry.url }}">{{ entry.title }}</a></h2>
        {{ entry.body }}
        <p>Written by {{ entry.author }} on {{ entry.postDate|date('M d, Y') }}</p>
    </article>
{% endblock %}

You don't need to create a Single for the Blog index page.

You can just create a template file: blog/index.html with:

{% extends "_layout" %}
{% set title = "Blog" %}

{% block content %}
    {% for entry in craft.entries.section('blog').find() %}
        <article>
            <h2><a href="{{ entry.url }}">{{ entry.title }}</a></h2>
            {{ entry.body }}
            <p>Written by {{ entry.author }} on {{ entry.postDate|date('M d, Y') }}</p>
        </article>
{% endblock %}

EDIT:

If it is a requirement for end users to be able to publish and edit content, other than blog entries, appearing on Blog index page via the CP, then a Single is the way to go.

  • Create custom field(s).
  • Create Single called Blog Index, or Blog Homepage, or something other than Blog.
  • Add custom field(s) to Blog Single entry type.
  • Entry Template: blog/index

In blog/index.html:

{% extends "_layout" %}
{% set title = "Blog" %}

{% block content %}
    {{ entry.customField }}

    {% for entry in craft.entries.section('blog').find() %}
        <article>
            <h2><a href="{{ entry.url }}">{{ entry.title }}</a></h2>
            {{ entry.body }}
            <p>Written by {{ entry.author }} on {{ entry.postDate|date('M d, Y') }}</p>
        </article>
{% endblock %}
  • Hi Andrea, thanks for taking the time to answer. Your answer is good for listing blog entries on the index page and linking to individual entries. But there is no way to put other content (not a blog entry) on the index page, for example I might want to have intro text describing what the blog is about. That's why I suggested a Single - it can have it's own fields, as well as pull in blog entries. – user1070143 Sep 5 '14 at 14:31
  • Indeed. If it is a requirement for end users to be able to publish and edit content appearing on Blog index page via the CP, then a Single is the way to go. Perhaps edit your original question to point this out? – Andrea DeMers Sep 5 '14 at 14:43
  • I've edited the original question as you suggested. Bit of a disjointed experience to have the blog main page and blog entries in different parts of the CP. – user1070143 Sep 5 '14 at 15:10

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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