Skip to content
themeforge
EN
Start free
Menu
  1. Home
  2. Section recipes
  3. Blog page
Recipe 5 steps

A blog page: posts, categories and page numbers

The main page of a blog: a heading and a couple of lines about the blog at the top, then categories, posts and page numbers. The client edits the heading and text like any page; the posts appear by themselves.

What you get

Markup archive-post.html
<body wp-fields-group="Blog">
<header class="blog-hero">
  <h1 wp="post-title">From the blog</h1>
  <p class="blog-hero__lead" fld-area="Blog lead">Notes from the roastery: new beans, brewing tips and events.</p>
</header>
<nav class="blog-cats" wp-term-query="category">
  <a class="blog-cats__link" href="#" wp="term-link"><span wp="term-title">Coffee</span> <span class="blog-cats__count" wp="term-count">5</span></a>
</nav>
<div class="posts" wp="posts">
  <article class="post-card">
    <a href="#" wp="post-link"><img src="images/news.jpg" alt="" wp="post-image"></a>
    <p class="post-card__date" wp="post-date">October 1</p>
    <h3><a href="#" wp="post-title-link">New autumn menu</a></h3>
    <div class="post-card__text" wp="post-excerpt">Pumpkin latte is back, and so is the apple pie.</div>
  </article>
</div>
<div class="posts__empty" wp="no-results">No posts yet</div>
<div class="pagination" wp-paginate="mid_size=1&prev_text=Newer&next_text=Older"></div>
</body>
In the admin Pages → Blog
Pages → Blog
  • Title: From the blog
Blog
Blog lead Notes from the roastery: new beans, brewing tips and events.
Settings → Reading
  • Posts page: Blog
  • Blog pages show at most: 6 posts
On the site blog page
From the blog

Notes from the roastery: new beans, brewing tips and events.

Coffee 5 Kitchen 3 Events 2
New autumn menu Oct 12
Why we roast on Mondays Oct 5
Newer 1 2 3 Older

The heading and intro belong to the “Blog” page; WordPress fills in the categories and posts.

Step by step

  1. Name the field group

    wp-fields-group on the <body> of archive-post.html: it builds the blog page template.

    <body wp-fields-group="Blog">
  2. Heading and intro

    wp="post-title" above the list shows the title of the “Blog” page, and fld-area is a field of that page. The client edits them like any page.

    <h1 wp="post-title">From the blog</h1>
    <p class="blog-hero__lead" fld-area="Blog lead">Notes from the roastery: new beans, brewing tips and events.</p>
  3. Categories with counts

    wp-term-query="category" goes through the blog’s categories. The sample is the first element: a wp="term-link" link with the name and the number of posts inside (wp="term-title", term-count).

    <nav class="blog-cats" wp-term-query="category">
      <a class="blog-cats__link" href="#" wp="term-link"><span wp="term-title">Coffee</span> <span class="blog-cats__count" wp="term-count">5</span></a>
    </nav>
  4. The list of posts

    wp="posts" is the main list of the page, the blog’s posts in order. Inside is a post card, and next to it a wp="no-results" block for an empty blog.

    <div class="posts" wp="posts">
      <article class="post-card">
        <a href="#" wp="post-link"><img src="images/news.jpg" alt="" wp="post-image"></a>
        <p class="post-card__date" wp="post-date">October 1</p>
        <h3><a href="#" wp="post-title-link">New autumn menu</a></h3>
        <div class="post-card__text" wp="post-excerpt">Pumpkin latte is back, and so is the apple pie.</div>
      </article>
    </div>
    <div class="posts__empty" wp="no-results">No posts yet</div>
  5. Page numbers

    wp-paginate on an empty block after the list; the “Newer” and “Older” labels go in the attribute’s value.

    <div class="pagination" wp-paginate="mid_size=1&prev_text=Newer&next_text=Older"></div>

What matters

  • Which page is the blog and how many posts it shows is set in Settings → Reading: “Posts page” and “Blog pages show at most”.
  • Categories without posts are left out of the list.
  • A single category’s page is a separate template: see the category page recipe.

Common mistakes

The build log is the “Logs” tab of your project on themeforge.pro; the free markup check shows the same notes.

Not like this
<div class="posts" wp="posts">
  <article class="post-card">
    <h3 wp="post-title">New autumn menu</h3>
  </article>
  <div class="pagination" wp-paginate="mid_size=1"></div>
</div>

Page numbers inside the list block: the build takes them for an extra card and drops them, so the site has none. The build notes this in the log.

Like this
<div class="posts" wp="posts">
  <article class="post-card">
    <h3 wp="post-title">New autumn menu</h3>
  </article>
</div>
<div class="pagination" wp-paginate="mid_size=1"></div>

Page numbers go in their own block after the list.

Not like this
<nav class="blog-cats" wp-term-query="category">
  <a href="#" wp="term-title">Coffee</a>
</nav>

wp="term-title" on a link prints the name, but the address stays #. The log stays silent.

Like this
<nav class="blog-cats" wp-term-query="category">
  <a href="#" wp="term-title-link">Coffee</a>
</nav>

term-title-link gives both the name and the address of the category.

Attributes in this recipe

Ready when you are

See your site’s WordPress admin before you pay.