|
Cookbook /
BalusBlogSummary: How Balu built his blog using pagelists
Version: 2007-08-17
Prerequisites: pmwiki-2.2.0 beta series
Status: beta
Maintainer: Balu
Discussion: BalusBlog-Talk
Questions answered by this recipe
DescriptionHow 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
ToDo
SetupBlog 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):
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 itAfter 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. ArchivesTo 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.
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.
Release Notes
CommentsSee discussion at BalusBlog-Talk See Also
Contributors |