How to use serendipity_fetchEntries ?

Creating and modifying plugins.
Post Reply
Dinges
Regular
Posts: 14
Joined: Fri Aug 12, 2005 3:33 pm

How to use serendipity_fetchEntries ?

Post 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.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: How to use serendipity_fetchEntries ?

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Dinges
Regular
Posts: 14
Joined: Fri Aug 12, 2005 3:33 pm

Post by Dinges »

Lol, I allready created a query that fetches them all subcategories. Maybe document such things?
Dinges
Regular
Posts: 14
Joined: Fri Aug 12, 2005 3:33 pm

Post by Dinges »

Nope, I just tried to use that method, it just still gives all categories :(
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Dinges
Regular
Posts: 14
Joined: Fri Aug 12, 2005 3:33 pm

Post 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"}
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply