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
<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>- Title: From the blog
- Posts page: Blog
- Blog pages show at most: 6 posts
Notes from the roastery: new beans, brewing tips and events.
Coffee 5 Kitchen 3 Events 2The heading and intro belong to the “Blog” page; WordPress fills in the categories and posts.
Step by step
Name the field group
wp-fields-group on the
<body>ofarchive-post.html: it builds the blog page template.<body wp-fields-group="Blog">
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>
Categories with counts
wp-term-query="category"goes through the blog’s categories. The sample is the first element: awp="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>
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 awp="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>
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.
<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.
<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.
<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.
<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.