Sidebar-stylePageList

Summary: See PagelistTemplateSamples? Status: Version: Prerequisites: pmwiki-2.0 Maintainer: Categories: Superceded Votes:

Question

How do I make a (:pagelist:) format whose output resembles that of

  
!Group A
* Page 1
* Page 2
* Page 3

!Group B
* Page 4
* Page 5
* Page 6

in order to automate sidebar updates? (For example, what if you wanted the sidebar to automatically list all normal pages in the Portfolio and Category groups?)

Answer

This recipe is superceded by PmWiki's use of PageListTemplates, from version 2.1.beta15 onwards.
See PagelistTemplateSamples#sidebar? for a sidebar pagelist template.

Insert the following code into your config.php:

  
### Creates the sidebar pagelist format, combination of JR and Hans' solutions plus Bronwyn's mods

## add fmt=sidebar to pagelist options.
## FPLSideBar provides a bullet list of pages organized by group,
## the group displayed as Header1, for use in a SideBar.
$FPLFunctions['sidebar'] = 'FPLSideBar';
function FPLSideBar($pagename, &$matches, $opt) {
 global $FPLSideBarStartFmt, $FPLSideBarEndFmt, $FPLSideBarGFmt,
   $FPLSideBarIFmt, $FPLSideBarOpt;
 SDV($FPLSideBarStartFmt,"<div class='fplsidebar'><ul>");
 SDV($FPLSideBarEndFmt,'</ul></div>');
 SDV($FPLSideBarGFmt,"</ul><p class='vspace'></p>\n<h1> 
   <a href='\$ScriptUrl/\$Group'>\$Group</a></h1>\n<ul class='fplsidebar'>\n");
 SDV($FPLSideBarIFmt,"<li><a href='\$PageUrl'>\$Title</a></li>\n");
 SDVA($FPLSideBarOpt, array('readf' => 0, 'order' => 'name'));
 $matches = MakePageList($pagename, array_merge($FPLSideBarOpt, $opt));
 if (@$opt['count']) array_splice($matches, $opt['count']);
 $out = array();
 foreach($matches as $pc) {
   $pgroup = FmtPageName($FPLSideBarGFmt, $pc['pagename']);
   if ($pgroup != @$lgroup) { $out[] = $pgroup; $lgroup = $pgroup; }
   $out[] = FmtPageName($FPLSideBarIFmt, $pc['pagename']);
 }
 return FmtPageName($FPLSideBarStartFmt, $pagename) . implode('', $out) .
            FmtPageName($FPLSideBarEndFmt, $pagename);
}
## turn off group name with the next line,
## comment it if you want the group name in the list.
#$FPLSideBarGFmt = "";

To use, put a pagelist directive in the appropriate page:

  (:pagelist group=Main fmt=sidebar list=normal:)

See the pagelist documentation? for more information on using the pagelist directive.

What does it do?

  • wraps the whole output of the pagelist directive in a div tag
  • starts each group with a whitespace paragraph, an H1, and then opens the bulleted list
  • closes each UL properly (AFAIK)
  • declares class='fplsidebar' for the div and ULs
  • leaves the built-in bygroup pagelist format available
  • can have group headings turned off
  • uses long page (:titles:)

New and Improved

This version is more search-engine friendly since it emulates with the new %sidehead% markup.

## Creates the sidebar pagelist format, combination of JR and Hans' solutions plus Bronwyn's mods
## $FPLFunctions is a list of functions associated with fmt= options
SDVA($FPLFunctions, array(
 'sidebar' => 'FPLSideBar',
 'bygroup' => 'FPLByGroup',
 'simple'  => 'FPLSimple',
 'group'   => 'FPLGroup'));
#
## FPLSideBarSB provides a bullet list of pages organized by group,
## the group displayed as %sidehead%, for use in a SideBar
function FPLSideBar($pagename, &$matches, $opt) {
 global $FPLSideBarStartFmt, $FPLSideBarEndFmt, $FPLSideBarGFmt,
   $FPLSideBarIFmt, $FPLSideBarOpt;
 SDV($FPLSideBarStartFmt,"<div class='fplsidebar'><ul>");
 SDV($FPLSideBarEndFmt,'</ul></div>');
 SDV($FPLSideBarGFmt,"</ul><p class='vspace'></p>\n<p class='sidehead'><a href='\$ScriptUrl/\$Group'>\$Group</a></p>\n<ul class='fplsidebar'>\n");
 SDV($FPLSideBarIFmt,"<li><a href='\$PageUrl'>\$Title</a></li>\n");
 SDVA($FPLSideBarOpt, array('readf' => 0, 'order' => 'name'));
 $matches = MakePageList($pagename, array_merge($FPLSideBarOpt, $opt));
 if (@$opt['count']) array_splice($matches, $opt['count']);
 $out = array();
 foreach($matches as $pc) {
   $pgroup = FmtPageName($FPLSideBarGFmt, $pc['pagename']);
   if ($pgroup != @$lgroup) { $out[] = $pgroup; $lgroup = $pgroup; }
   $out[] = FmtPageName($FPLSideBarIFmt, $pc['pagename']);
 }
 return FmtPageName($FPLSideBarStartFmt, $pagename) . implode('', $out) .
            FmtPageName($FPLSideBarEndFmt, $pagename);
}
## turn off group name with the next line,
## comment it if you want the group name in the list.
#$FPLSideBarGFmt = "";

Notes and Comments

  • This recipe was last tested on PmWiki version: 2 beta 48
  • This recipe requires at least PmWiki version: and (any other recipes)

See Also

Contributors


Category: Layout