|
Cookbook /
AutoCreateCategorySummary: Automatically creates category pages for all tags in the page text
Version: 0.9 2008-11-27
Prerequisites:
Status: BETA
Maintainer: Michael Selbmann
Categories: Administration
Questions answered by this recipeHow can I create pages for all categories which are linked in my text? DescriptionAutomatically creates category pages for all categories which are linked in the page text. NotesI needed that for an intranet. Pages had to be linked to categories. These categories had to be listed in the navigation. pagelist didn't work. InstallationPut this in your local/config.php.
function AutoCreateCategoryPage($pagename, &$page, &$new)
{
if(isset($_POST['text']) && (strpos(@$new['text'], '[[!') == true) && (preg_match('/^Site\.|^PMWiki\.|WikiSandbox/', $pagename) == false))
{
$AutoCreateCategory = Array();
// get text
$txt = preg_replace('/[\n\a\t]/', '', @$new['text']);
while(strpos($txt, '[[!'))
{
$curcat = preg_replace('/^.*?\[\[!(.*?)\]\].*$/', '$1', $txt);
$txt = str_replace('[[!' . trim($curcat) . ']]', '', $txt);
array_push($AutoCreateCategory, $curcat);
}
# CreateCategoryPages
foreach((array)@$AutoCreateCategory as $x)
{
$page = "Category.$x";
if(!PageExists($page)) # Create it
{
$ntext['comment'] = 'Created by System';
$ntext['ctime'] = $Now;
}
WritePage($page, $ntext);
}
}
}
array_unshift($EditFunctions, 'AutoCreateCategoryPage');
Now you can show the category links with that code: (:pagelist group=Category name=-Category fmt=#title list=normal :) To build a category page, that shows all linked pages, I use a
!Pages in category: {$Name}
(:pagelist link=Category.{$Name} list=normal fmt=#group:)
ContributorCommentsWhat do you think about my first recipe? Thank you. Michael Selbmann |