Category ID known - how to retrieve path?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Category ID known - how to retrieve path?

Post by Don Chambers »

From an index.tpl file, I want to get the path to a category's entries (ie, http://www.mysite.com/categories/2-examplecategory). I already know the category number (ie 2). And it probably has to work regardless of URL rewriting. Is this possible?

I suppose it would be the equivalent of {$entry_category.category_link} in entries.tpl, but this is from index.tpl.

Ideas???
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Category ID known - how to retrieve path?

Post by garvinhicking »

Hi!

I guess you'd need a custom smarty function to wrap around the s9y api "serendipity_categoryURL()" function call to put into your templates' config.inc.php file.

Or you could link to index.php?serendipity[category]=2

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/
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers »

Thanks Garvin - the serendipity_categoryURL() did the trick, along with the expert input of Judebert who I constantly harass anytime I see him using IM!!! :lol:
=Don=
tpost
Regular
Posts: 77
Joined: Fri Sep 21, 2007 1:45 am

Post by tpost »

*bump*

Can somebody outline what is needed in the config.inc.php file?

I couldn't find any documentation on the serendipity_categoryURL() function.
A link to the documentation could help as well!

Thanks in advance!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

The documentation to that function can be found inside include/functions_permalinks.inc.php.

A sample code in the config.inc.php could be:

Code: Select all

function smarty_categoryURL($params, &$smarty) {
  $data = serendipity_fetchCategoryInfo($params['id']);
  return serendipity_categoryURL($data);
}

$serendipity['smarty']->register_function('smarty_categoryURL', 'smarty_categoryURL');
then you can use this inside your .tpl files:

Code: Select all

<a href="{smarty_categoryURL id=7}">Category #7</a>
HTH
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/
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers »

Garvin's reply looks a lot simpler than what I am using.
=Don=
tpost
Regular
Posts: 77
Joined: Fri Sep 21, 2007 1:45 am

Post by tpost »

Thanks Garvin!
That helped!
Post Reply