Page 1 of 1
How to use serendipity_fetchEntries ?
Posted: Fri Aug 12, 2005 10:39 pm
by Dinges
I use the serendipity_fetchEntries function to fetch the contents of category, however, it does not support the subcategories to be displayed
How should I use the various parameters to get the subcategory listing?
Code: Select all
serendipity_fetchEntries(null, false, $params["limit"], false, false, 'timestamp DESC', 'c.categoryid = '.$params["category"]);
is what I use as of yet.
limit = the number of articles, category = the category id, I allready tried adding:
Code: Select all
OR c.parentid = '.$params["category"]
Which added support for the categorys directly beneath it, but still not travels down to the deepest link.
I figure there must be a function that gets all subcategory's of a specific category.
Re: How to use serendipity_fetchEntries ?
Posted: Sat Aug 13, 2005 5:30 pm
by garvinhicking
Before calling the serendipity_fetchEntries you'll need to set $serendipity['GET']['categoryid'] to the category you want to fetch!
This is sadly a small problem in the API function as it doesn't take the category as a parameter. This is because of some problematic compatibility issues. It could be fixed easily, I just haven't had the time to add a new parameter to the function.
Regards,
Garvin
Posted: Sat Aug 13, 2005 7:57 pm
by Dinges
Lol, I allready created a query that fetches them all subcategories. Maybe document such things?
Posted: Sat Aug 13, 2005 9:47 pm
by Dinges
Nope, I just tried to use that method, it just still gives all categories

Posted: Sun Aug 14, 2005 2:35 am
by garvinhicking
Can you show the code you exactly use?
The fetchEntries function is used to display all entry of a category and all its child categories - it works in the s9y framework, so there must just be a simple error in your method call. Maybe a missing "global $serendipity" or so.
Regards,
Garvin
Posted: Sun Aug 14, 2005 3:07 pm
by Dinges
Code: Select all
<?php
$serendipity['smarty']->register_function('category_listing', 'category_listing');
function category_listing($params, &$smarty) {
global $serendipity;
/*
//Get all categories, subcategories and subcategories and subcategories :P
<< Truncated: Old code to fetch all categories. (commented) >>
*/
//Set serendipity to fetch the correct category
$serendipity['GET']['categoryid'] = $params["category"];
//Fetch category content
$category_content = serendipity_fetchEntries(null, true, $params["limit"]);
//Assign the title to smarty ass
$smarty->assign("listing_title", $params["title"]);
//In case there is a result
if ($category_content != "1") {
//Get links and bodies
for ($i=0; $i<count($category_content); $i++) {
//Body needed?
if ($params["fullpost"] == 1) {
$category_content[$i]["entry_body"] = serendipity_fetchEntry('id', $category_content[$i]["id"]);
$category_content[$i]["link_author"] = "authors/".$category_content[$i]["authorid"]."-".str_replace(" ", "-", $category_content[$i]["author"]);
for ($j=0; $j<count($category_content[$i]["categories"]); $j++)
$category_content[$i]["categories"][$j]["category_link"] = "/categories/".$category_content[$i]["categories"][$j]["categoryid"]."-".$category_content[$i]["categories"][$j]["category_name"];
}
$category_content[$i]["link"] = "/archives/".$category_content[$i]["id"]."-".str_replace(" ", "-", $category_content[$i]["title"]).".html";
//print_r($category_content[$i]["entry_body"]);
}
//Assign to smarty and process template
$smarty->assign("category_content", $category_content);
return $smarty->fetch("entries_cat_list.tpl");
}
}
?>
Pasted this in config.inc.php, it is still just a draft as the links should be corrected to use internal routines.
Smarty code:
Code: Select all
{category_listing category=2 limit=1 fullpost=1 title="Laatste blogpost"}
{category_listing category=2 limit=1,4 title="Oudere blogposts"}
Posted: Mon Aug 15, 2005 12:45 pm
by garvinhicking
I'm awfully sorry. I told you, in my lazyiness, the variable to set is $serendipity['GET']['categoryid']. In fact it is $serendipity['GET']['category'], without the "id" part.
Sorry for that!
Regards,
Garvin