Blog Pages

Håkan Edling edited this page Sep 20, 2018 · 2 revisions

For general information of the different rules & components available when defining content types, please refer to Content Type Anatomy.

Blog pages work in the same way as regular pages except that they also function as an Archive for Posts. Your site can contain multiple blog pages, each with its unique set of Categories, Tags and Posts.

If your blog page has the slug /news, then the posts for that blog will have the slugs /news/my-post-slug. You also get a lot of archive functionality out-of-the-box, read more about that under Middleware.

Defining A Blog Page Type

A blog page is defined the same way as a normal page type except that the model should derive from BlogPage<T> instead of Page<T>.

[PageType(Title = "News Page")]
public class NewsPage : BlogPage<NewsPage>
    [Region(Title = "Header")
    public MarkdownField Header { get; set; }        

The main difference between the different base classes is that BlogPage<T> contains an additional property Archive which contains the posts loaded by the current archive request. To load a blog page from the api you use:

var page = api.Archives.GetById<NewsPage>(id, page, year, month);

If you only want to load the page without the post archive, you can get it from the regular page api:

var page = api.Pages.GetById<NewsPage>(id);

To import this page type during your application startup you add the following line to your Configure method.

var builder = new PageTypeBuilder(api)

As you can see the PageTypeAttribute allows you to set the title that will be displayed in the manager interface. If this property is left blank the class name is used.

Disable Blocks For Blog Page Types

If you don't want to use the Block Editor you can disable this for your Blog Page Type by adding the following to the Attribute.

[PageType(Title = "Markdown Page", UseBlocks = false)]

Blog Page Routing

Routing for Blog Pages work in the same way as for regular pages except that the default route is /archive. For more documentation about routing, see Page Types.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.