Vernon Thommeret schrieb:
Hi,
I'm trying to come up with code that can tell me whether or not a
given category has articles or not. Naturally, I borrowed some code
from CategoryPage.php. This is what I got up to:
$res2 = $dbr->select(
array( 'page', 'categorylinks' ),
array( 'page_title' ),
array( 'cl_from = page_id', 'cl_to' => $title->getArticleID()),
$fname,
array('LIMIT' => 1 ));
echo $res2;
echo $dbr->fetchObject($res2);
If you only want to check, if a category has articles, this would be faster:
$catCount = $dbr->selectField( 'categorylinks', 'count(*)',
array('cl_to' => $title->getDbKey() ), $fname);
This statement only counts the number of articles pointing to the
category, or do you need the name of each article?
Vernon Thommeret schrieb:
Thanks for your help. I got the code working
perfectly. One thing,
however, is that the category will never update on their own. I have
to modify LocalSettings.php, and then it reparses the page. Is this
something I have to live with?
Seems to be coincidal. Categories get updated by job queue, meaning as
long as you have entries in table job, you need to work with your wiki,
as it executes one job entry for every click.
GunterS