Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

BalusBlog

Summary: How Balu built his blog using pagelists
Version: 2007-08-17
Prerequisites: pmwiki-2.2.0 beta series
Status: beta
Maintainer: Balu
Categories: Blog CMS
Discussion: BalusBlog-Talk

Questions answered by this recipe

  • How can I create a blog using as much of PmWiki's core mechanisms as possible?
  • Can I create a blog based on PmWiki without specialized extensions?

Description

How Balu built his blog using pagelists

At the end of 2005 I had some ideas what features I would like in a blogging setup using PmWiki. Many of those required specialized PHP extensions to PmWiki. After a long time without using PmWiki I just came back and noticed that you can do nearly all of it by using only PmWiki's core features.

Features

  • display a number of entries on the blog homepage
  • display date based "archives" using pages like
    • "2007" - overview of all posts from that year,
    • "2007-08" - overview of all posts from that month,
    • "2007-08-12" - overview of all posts for that day
  • templated overview and detail pages, so you don't have to update all entries when changing the layout
  • tag entries using the PmWiki Categories

ToDo

  • add support for feeds
  • add support for comments
  • ???

Setup

Blog entries:

All blog entries have go inside a group like "Blog". This is supposed to be some kind of repository that will be used to put all other pages including the overview, archives and the entry pages together using templates. Each blog entry in this group needs to have a name that is formatted like "YYYY-MM-DD-whatever". The date string at the beginning is important, while "-whatever" can be anything you like (but not empty, because that will conflict with the overview page for that day).

Hint: If you know you are going to create multiple entries for a day "-whatever" should probably be "-X-whatever", with X being an index number for each entry. This helps keeping the entries in the correct order since they are sorted by their page name.

The format for each entry has to be as follows:

(:if false:)
Title: XXXXX
More: read more...

[[#entrybody]]
XXXXX

[[#extendedbody]]
XXXXX

If you want to make your life a lot easier, check out how to make an edit template for new entries using the example above.

Title and More are optional pagetext variables. While the Title is replaced with a default "no title", More will simply not be displayed if not set. But if you set More, you will also have to use the #extendedbody-anchor to avoid displaying the extended body on the overview pages, otherwise you can remove it.

You can add other pagetext variables to each entry like e.g. Tags to sort it into categories.

Security:

To make sure that only a few people can create new entries you need to edit the group attributes for your blog group and restrict rights to edit pages in there (see passwords).

Overview template:

The overview page (list of entries) is based on a template that goes into a page named BlogOverviewTemplate:

! Overview template 

You can extend the following default values additional variables as you like.

:TitleDefault: no %em%Title%%

[@
[[#blogentries]]
(:template defaults order=-name name=????-??-??*:)
(:div class="blogpost":)
! (:if equal "{=$:Title}" "":){$:TitleDefault}(:else:){=$:Title}(:ifend:)
(:include {=$FullName}#entrybody#extendedbody:)
(:if !equal "{=$:More}" "":)[[{=$FullName}#extendedbody | {=$:More}]](:ifend:)

[[{=$FullName} | Permalink]]
(:if auth edit:)[[{=$FullName}?action=edit | edit entry]](:ifend:)
(:divend:)
[[#blogentriesend]]
@]

You can of course extend the above template using common PmWiki variables or additional pagetext variables like e.g. Tags that are defined in your entries. Use Title and TitleDefault as examples if you want to do so.

To use this template, add the following line to your blog homepage (Blog.HomePage or Blog.Blog):

(:pagelist fmt=BlogOverviewTemplate#blogentries group={$Group} count=10:)

If you want to list your blog entries on other pages, change the group-parameter to point to your blog group. You can easily display only the latest entry using count=1.

Detail view template:

Displaying the detailed view of an entry is done using a template in the page BlogDetailTemplate:

(:div class="blogpost":)
!! (:if equal "{*$:Title}" "":){BlogOverviewTemplate$:TitleDefault}(:else:){*$:Title}(:ifend:)
(:include {*$FullName}#entrybody#:)

[[{*$FullName} | Permalink]]
(:if auth edit:)%edit%[[{*$FullName}?action=edit | edit entry]]%%(:ifend:)
(:divend:)

To use this template, create a GroupHeader page in your blog using the following content:

(:if name ????-??-??[-_]*:)
(:include BlogDetailTemplate:)
(:ifend:)

The condition above makes sure that the BlogEntryDetailTemplate is only used for blog entry pages.

Test it

After you've finished the setup as described above and created two or more entries, check out your blog group homepage. There should be a list of the entries you've just created. Using the permalink you can get to the detailed view of one entry.

Archives

To create archive pages like "2007" (shows all entries for 2007), "2007-08" (all entries for August 2007) or "2007-08-17" (show all entries for that day), you can create the corresponding pages using a line similar to the one on the blog homepage.

(:pagelist fmt=BlogOverviewTemplate#blogentries group={$Group} name=2007-*:)

This restricts the list of entries to all pages starting with "2007-" and can easily be modified to work for a monthly or daily view.

However creating all archive pages manually is stupid work that can be avoided using a trick. By extending the GroupHeader with the following lines PmWiki creates the archive pages on the fly as they are called.

(:if name ????,????-??,????-??-??:)
(:pagelist fmt=BlogOverviewTemplate#blogentries group={$Group} name={$Name}*:)
(:ifend:)

If you call one of those pages you'll notice that below the list of entries is a note saying something like "The page "Blog/2007" doesn't exist. (Create Blog.2007)". PmWiki does not know we are going to display some kind of "virtual" page here.

To avoid the message (and the 404 "page not found" header PmWiki sends also) you need to modify your local/config.php and add the following lines:

// avoid page not found for virtual blog pages
if (preg_match('/^Blog(\.|\/)....(-..(-..)?)?$/', $pagename)) {
    $DefaultPageTextFmt = '';
    $PageNotFoundHeaderFmt = 'HTTP/1.1 200 Ok';
}

Make sure to replace "Blog" with the name of your blog group.

!! Notes

Release Notes

  • 2007-08-17: Major update
    • restructured the recipe to keep everything blog related in one group (not split across multiple ones)
    • also avoid problems with the "virtual" pages from earlier versions (like 404 headers, etc)
    • simplified all templates to make it easier to understand for beginners - experts still can extend them as they know how to do it
  • 2007-08-12:
    • changed links built with $ScriptUrl (avoiding the "create page" markers for non existent pages) to "?action=browse",
    • made this release a beta version
  • 2007-08-12: published first alpha version

Comments

See discussion at BalusBlog-Talk

See Also

Contributors

  • Balu is the creator / maintainer
  • Pm gave a lot of hints on the irc channel #pmwiki and provides us with this great piece of software
Edit - History - Print - Recent Changes - Search
Page last modified on December 15, 2007, at 02:10 PM