[pmwiki-devel] About categories
Simon
nzskiwi at gmail.com
Wed Jan 22 00:04:05 PST 2025
Thanks for this, this is most useful.
Yes I meant the scenario where there are no 'incoming links' to the
category page, so thanks very much for the code
For the scenarios:
1) a call a page Main/NoSuchPage: the page Site.PageNotFound displays
2) a call Category/NoSuchPage: a blank page displays (plus whatever is in
the group header or group footer).
I suspect this may be in StdMarkup.php, line 391 viz
# This is a temporary workaround for blank category pages.
# It may be removed in a future release (Pm, 2006-01-24)
if (preg_match("/^$CategoryGroup\\./", $pagename)) {
SDV($DefaultPageTextFmt, '');
SDV($PageNotFoundHeaderFmt, 'HTTP/1.1 200 Ok');
}
I'll try your local configuration override, but take into account the
variable $CategoryGroup
thanks again
Simon
On Sun, 19 Jan 2025 at 23:16, Petko Yotov <5ko at 5ko.fr> wrote:
> On 18/01/2025 21:45, Simon wrote:
> > Category pages are perhaps the only time where PmWiki renders pages
> > when they do not exist.
>
> PmWiki renders the Site.PageNotFound text if any requested page doesn't
> exist, with a header "HTTP/1.1 404 Not Found".
>
> For Category pages which does not exist, the Site.PageNotFound text is
> not shown, the header is "HTTP/1.1 200 Ok" and the Group Footer includes
> a pagelist with backlinks.
>
> This can be overridden in local configuration, for example:
>
> # Show PageNotFound for category pages that don't exist
> if (preg_match("/^Category\\./", $pagename)) {
> $DefaultPageTextFmt = '(:include Site.PageNotFound:)';
> $PageNotFoundHeaderFmt = 'HTTP/1.1 404 Not Found');
> }
>
> > Is it possible to test, in code, if a category exists?
> > (I want to count in TotalCounter hits on Category pages for categories
> > that do exist only, as TotalCounter (no longer) counts (the very many)
> > hits to pages that do not exist).
>
> It depends on what does "category exists" means. If it is "Category page
> exists", you have the PageExist($pagename) function.
>
> Look up the documentation about $AutoCreate on how to automatically
> create category pages when saving a page linking to them.
>
> OTOH if "category exists" means "there are currently incoming links",
> you can check if a pagelist has any pages, then the category "exists".
>
> # if you call your code before stdconfig.php
> include_once("$FarmD/scripts/pagelist.php");
>
> # define array and options
> $list = [];
> $opt = [ 'link' => $pagename ];
> FPLTemplatePageList($pagename, $list, $opt);
>
> # $list has now pages that link to $pagename.
> if($list) {} # 1+ incoming links, category "exists"
>
>
> > Is it possible to have PmWiki not render a category page if the
> > category does not exist?
>
> To display the Site.PageNotFound text when there are no incoming links,
> you can place in the pagelist "template none" section:
>
> (:include Site.PageNotFound:)
>
> I would probably create a pagelist template for the Category listings
> separate from the search templage.
>
> Petko
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-devel/attachments/20250122/4e95412d/attachment.html>
More information about the pmwiki-devel
mailing list