Fox Blog

Summary: How to build a blog with Fox
Version: 2006-04-03a
Prerequisites: pmwiki 2.2.0
Status: not working with current Fox
Maintainer: HansB?
Categories: CMS Blog Fox

Questions answered by this recipe

How can I add a blog to my wiki?


The recipe instructions at present will not work with the current Fox (see comments below). A new FoxBlog based on FoxForum is planned and should be ready by the end of this month. My sincerest apologies to all who tried the instructions below and ended up with a half working blog, especially with commenting not tied into the blog posts properly. HansB? November 10, 2007, at 03:59 AM

You can add a blog by using Fox with standard Input? controls and PageLists.

The following gives a simple example how to built a blog with Fox. The easiest setup is by having all blog pages in one group. But this should also work with blog pages being in various groups.

New blog pages are getting created on a page NewBlogPage:

(:fox form1 #top template=Site.FoxBlogTemplate redirect=1:)
||width=100% center
|| '''Page Name:'''||(:input text target size=30:) ||
|| '''Title:'''||(:input text titletxt size=30:) ||
||'''Content:''' || ||
||(:input textarea text cols=70 rows=15:) ||||
|| Author:||(:input text author value="{$Author}" size=30:) 
  (:input submit post Post:) ||
(:foxend form1:)

This fox form uses Site.FoxBlogTemplate:

(:title {$$titletxt}:)%comment%[[!Blog]]
>>div1 blogpost<<
>>rfloat frame<<
by {$$author} on {$$(date d.m.Y - H:i)} &nbsp;
(:if auth edit:)[[Comments.{$Group}-{$Name}?action=edit|edit comment page]](:if:)
!!!!!Comments: {Comments.{$Group}-{$Name}$FoxPostCount}
(:include Comments.{$Group}-{$Name}:)
(:include Site.FoxCommentBox:)

Each new blog page includes a FoxCommentBox, by which a visitor can posts a comment. All comments to a blog page are stored on a separate page in a Comments group, and included in the blog page.

With the following code added to config.php any attempt to browse (read) a Comments page directly results in a redirection to the blog page (where the comments are included).

# jumping from Comments.Group-Name to Group.Name when browsing
$pagename2 = preg_match('/^Comments[\/\.](.*?)-(.*)$/',$pagename,$matches);
  if ($pagename2!=0) $pagename2=$matches[1].'/'.$matches[2];
  if ($action=='browse' && $pagename!=$pagename2) Redirect($pagename2); 

This mechanism of tying a comment page to a blog page is much simpler than what I built for BlogSimple? (using CommentBoxPlus?).

Now we need some clever pagelist markup to display blog pages and lists of new blog pages and new comments:
First add these pagelist formats to Site.LocalTemplates:

Includes whole pages, with titles as links to the pages, 
separated by a horizontal rule underneath each page&#146;s content. 
Edit link at right. Comment link at right. creation date.
(:if auth edit:)
(:include {=$FullName}##blogend:)
(:if lt 1 {Comments.{=$Group}-{=$Name}$FoxPostCount} :)
[[{=$FullName}#comments| {Comments.{=$Group}-{=$Name}$FoxPostCount} Comments]]
(:if equal 1 {Comments.{=$Group}-{=$Name}$FoxPostCount} :)
[[{=$FullName}#comments| 1 Comment]]
(:if !exists Comments.{=$Group}-{=$Name} :)
[[{=$FullName}#commentbox| Add Comment]]
>>rfloat<<created {=$BlogDate} -- 
(:if equal {>$Group}:)
(:title {$Title}:)(:if:)

pagelist of spaced blog titles for sidebar, without group 
heading, with simple creation date
[[#blogdatedtitles]](:if equal {<$Group}:)
[-{=$BlogDateSimple} - -]
* [[{=$FullName}|{=$Title}]]
(:if equal {>$Group}:)

pagelist of spaced blog titles for sidebar, without group 
heading, with simple modification date
[[#commentsdatedtitles]](:if equal {<$Group}:)
[-{=$LastModifiedDate} - -]
* [[{=$FullName}#post{=$FoxCount}|{=$Title}]]
(:if equal {>$Group}:)

These pagelist formats are variations of what is used in BlogSimple?. In order for them to work they need also some special date pagevariables, defined in config.php:

# add pagevariable {$BlogDateSimple} as page creation date
$FmtPV['$BlogDateSimple'] = 'strftime("%a %d %b", $page["ctime"])';

# add pagevariable {$LastModifiedDate}
$FmtPV['$LastModifiedDate'] = 'strftime("%a %d %b", $page["time"])';

So now we need to add some special pagelists, pulling it all together:
On the blog homepage, where you want to have a number of blog pages included, add (put the pagelist markup on one line!!):

!!!Blog Index
(:pagelist Category.Blog name=-Site.FoxBlogTemplate 
  list=normal fmt=#foxblog order=-ctime include=10 :)

FoxBlogTemplate adds a hidden Blog category link to each new blog page, and pagelist will list pages with these. The example uses ten pages to be included. The included blog pages only display up to the anchor #blogend (specified in the pagelist fmt used), so any comments and the commentbox are not displayed on this blog homepage.

To get a list of the latest ten new blog pages we can add this to the SideBar or RightBar (put the pagelist markup on one line!!):

!!!!Recent Posts
(:pagelist Category.Blog name=-Site.FoxBlogTemplate 
   list=normal fmt=#blogdatedtitles order=-ctime count=10 :)

And to get a list of the latest comments, with link to the comment (put the pagelist markup on one line!!):

!!!!Recent Comments
(:pagelist group=Comments list=normal 
   fmt=#commentsdatedtitles order=-time count=10 :)

See working FoxBlog example: FoxBlog


Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".


Did Fox release 2007-04-13 break FoxBlog? Neighter breakpage nor FoxCount appear to work with the new Fox release. How to put them back? JHJ, 18.5.2007

Yes it did, sorry! FoxBlog needs to be reworked, same as FoxForum was. Fox does not use $FoxCount to set a page attribute counter any longer. Instead (with FoxForum) it uses a method which sets a PTV FoxCount, via a filter extension. Same goes for breakpage. The new FoxBlog in development will be similar to FoxForum, in fact built on it, and using display templates. I changed this behaviour to make Fox more standard complient.

To put it back would need modifications to fox.php. Probably these:

Add ca. line 280 after    $newpage = $page;
   $id = $newpage['foxcount'] = $page['foxcount']+1;

Add to the end:
## action=foxinit for resetting foxcount
function FoxHandleInit ($pagename) {
    $page = RetrieveAuthPage($pagename, 'attr', true);
    $page['foxcount'] = 0;
    $newpage = $page;
    UpdatePage($pagename, $page, $newpage);
} //}}}

# index counters from page
$FmtPV['$FoxCount'] = '$page["foxcount"]';
$FmtPV['$FoxCountInc'] = '$page["foxcount"]+1';
$FmtPV['$FoxCountDec'] = '$page["foxcount"]-1';

I also dropped automatic creation of id anchors in posts, to simplify things, and as anchors can be added via a template. HansB? May 19, 2007, at 01:34 AM

Is this recipe dead? The comments above (from 2007) say that it will be complete in one month, but there seems to have been no further activity. Please advise.

Matt September 27, 2008, at 10:31 PM

See Also