get category_id and the id's of it's sub categories
Moderators: pe7er, General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
- djemmers
- Joomla! Intern
- Posts: 90
- Joined: Thu May 22, 2008 7:09 am
get category_id and the id's of it's sub categories
hi
I am wondering how I can get the current category_id of a page and the id's of the subcategories throug php commands
I found this in the API, but don't know how to use it:
http://docs.joomla.org/API16:JCategories
I am wondering how I can get the current category_id of a page and the id's of the subcategories throug php commands
I found this in the API, but don't know how to use it:
http://docs.joomla.org/API16:JCategories
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
-
- Joomla! Explorer
- Posts: 349
- Joined: Mon Dec 15, 2008 11:10 am
Re: get category_id and the id's of it's sub categories
Me to want to know this...
Anybody that can help?
Anybody that can help?
-
- Joomla! Apprentice
- Posts: 16
- Joined: Fri Jan 21, 2011 3:02 pm
Re: get category_id and the id's of it's sub categories
It depends wether your menu item points to an single article or a blog or list view of articles in a category.
in second case you can catch the id by:
Be aware that if you display a single article you will get the article id, not category id. You can check in which view you are by:
returning 'article' string when displaying single article.
Once having the category id it should be easy to get the child categories:
http://docs.joomla.org/API16:JCategories/get
When in Single Article View, i actually dont know how to retrieve the category id, im sorry
in second case you can catch the id by:
Code: Select all
$catID = JRequest::getVar('id')
Code: Select all
$view = JRequest::getVar('view');
Once having the category id it should be easy to get the child categories:
http://docs.joomla.org/API16:JCategories/get
When in Single Article View, i actually dont know how to retrieve the category id, im sorry
- djemmers
- Joomla! Intern
- Posts: 90
- Joined: Thu May 22, 2008 7:09 am
Re: get category_id and the id's of it's sub categories
tnx for the reply,
but I can't seem to get the child categories...
I tried
gives:Fatal error: Call to undefined function get()
so I am not calling the get function correctly.
can you tell me what I should do?
but I can't seem to get the child categories...
I tried
Code: Select all
jimport( 'joomla.application.categories' );
$catID = JRequest::getVar('id');
echo $catID."<br/>";
print_r(get($catID));
so I am not calling the get function correctly.
can you tell me what I should do?
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
-
- Joomla! Apprentice
- Posts: 16
- Joined: Fri Jan 21, 2011 3:02 pm
Re: get category_id and the id's of it's sub categories
Try JCategories::get($catID)
- djemmers
- Joomla! Intern
- Posts: 90
- Joined: Thu May 22, 2008 7:09 am
Re: get category_id and the id's of it's sub categories
Code: Select all
$catID = JRequest::getVar('id');
echo $catID;
$test=JCategories::get($catID);
print_r($test);
78
Fatal error: Call to undefined method plgSystemJumi::_load() in /home/tornooi/domains/tornooi.net/public_html/joomla160/libraries/joomla/application/categories.php on line 160
does that mean the problem lies in jumi?
I think not because I can do things like:
Code: Select all
$exdb = & JDatabase::getInstance( $option );
if ( is_a($exdb, 'JException') ) {
$msg = 'Unable to connect to the target database';
echo $msg;
error_log( $msg );
return false;
}
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
- djemmers
- Joomla! Intern
- Posts: 90
- Joined: Thu May 22, 2008 7:09 am
Re: get category_id and the id's of it's sub categories
I tried:
same error:
Fatal error: Call to undefined method plgSystemJumi::_load() in /home/tornooi/domains/tornooi.net/public_html/joomla160/libraries/joomla/application/categories.php on line 160
Code: Select all
$catID = JRequest::getVar('id');
echo $catID;
$test= & JCategories::get($catID);
print_r($test);
Fatal error: Call to undefined method plgSystemJumi::_load() in /home/tornooi/domains/tornooi.net/public_html/joomla160/libraries/joomla/application/categories.php on line 160
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
-
- Joomla! Apprentice
- Posts: 16
- Joined: Fri Jan 21, 2011 3:02 pm
Re: get category_id and the id's of it's sub categories
jimport('joomla.application.categories');
$categories = new JCategories('com_content');
$subCategories = $categories->get($catID);
that worked for me, where 'com_content' is the extension
*updated*
$categories = new JCategories('com_content');
$subCategories = $categories->get($catID);
that worked for me, where 'com_content' is the extension
*updated*
- djemmers
- Joomla! Intern
- Posts: 90
- Joined: Thu May 22, 2008 7:09 am
Re: get category_id and the id's of it's sub categories
ok, now the error is gone but I can't get the subcategories.
gives
78
JCategories Object ( [_nodes:protected] => [_checkedCategories:protected] => [_extension:protected] => c [_table:protected] => c [_field:protected] => c [_key:protected] => c [_statefield:protected] => c [_options:protected] => com_content )
How do I know what extention I use?
and what does the "protected" mean?
Code: Select all
$catID = JRequest::getVar('id');
echo $catID;
jimport('joomla.application.categories');
$categories = new JCategories('com_content');
print_r($categories);
$subCategories = $categories->get($catID);
print_r($subCategories);
78
JCategories Object ( [_nodes:protected] => [_checkedCategories:protected] => [_extension:protected] => c [_table:protected] => c [_field:protected] => c [_key:protected] => c [_statefield:protected] => c [_options:protected] => com_content )
How do I know what extention I use?
and what does the "protected" mean?
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
- djemmers
- Joomla! Intern
- Posts: 90
- Joined: Thu May 22, 2008 7:09 am
Re: get category_id and the id's of it's sub categories
I also posted this in a dutch forum
http://forum.dutchjoomla.org/showthread.php?t=124152
no luck yet...
http://forum.dutchjoomla.org/showthread.php?t=124152
no luck yet...
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
-
- Joomla! Apprentice
- Posts: 31
- Joined: Mon Nov 17, 2008 2:41 pm
Re: get category_id and the id's of it's sub categories
This worked out for me.
Hopefully this will work for others.
To get the category id (whether viewing article or category blog), I use this...
To get the sub categories of the current category (or category of the article), use this...
Hopefully this will work for others.
To get the category id (whether viewing article or category blog), I use this...
Code: Select all
function getArticleCategory($id) {
$db = & JFactory::getDBO();
if (JRequest::getCmd('view', 0) == "category") {
return JRequest::getInt('id');
} elseif (Jrequest::getCmd('view', 0) == "article") {
$temp=explode(":",JRequest::getInt('id'));
$query = "SELECT catid FROM #__content WHERE id = ".$temp[0];
$db->setQuery( $query );
$items = $db->loadResult();
return $items;
}
}
To get the sub categories of the current category (or category of the article), use this...
Code: Select all
function getList(&$params) {
$categories = JCategories::getInstance('Content');
$article_id = JRequest::getInt('id');
$category = $categories->get(modArticleSubcategoriesHelper::getArticleCategory($article_id));
$items = $category->getChildren();
if($params->get('count', 0) > 0 && count($items) > $params->get('count', 0)) {
$items = array_slice($items, 0, $params->get('count', 0));
}
return $items;
}
- djemmers
- Joomla! Intern
- Posts: 90
- Joined: Thu May 22, 2008 7:09 am
Re: get category_id and the id's of it's sub categories
hi tnx for offering your sollution.
But it doesn't seem to work for me
first part works fine (but that was the part I got working too)
for the second part I get following error:
Fatal error: Class 'modArticleSubcategoriesHelper' not found in /home/tornooi/domains/tornooi.net/public_html/joomla160/jumifiles/events.php on line 63
and line 63 is:
I also noticed that $params is empty
As I said, I use jumi to execute the file
if I use print_r on $categories I get:
anny suggestions?
But it doesn't seem to work for me
first part works fine (but that was the part I got working too)
for the second part I get following error:
Fatal error: Class 'modArticleSubcategoriesHelper' not found in /home/tornooi/domains/tornooi.net/public_html/joomla160/jumifiles/events.php on line 63
and line 63 is:
Code: Select all
$category = $categories->get(modArticleSubcategoriesHelper::getArticleCategory($article_id));
As I said, I use jumi to execute the file
if I use print_r on $categories I get:
Code: Select all
ContentCategories Object ( [_nodes:protected] => [_checkedCategories:protected] => [_extension:protected] => com_content [_table:protected] => #__content [_field:protected] => catid [_key:protected] => id [_statefield:protected] => state [_options:protected] => Array ( [table] => #__content [extension] => com_content [access] => true [published] => 1 ) )
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
-
- Joomla! Apprentice
- Posts: 31
- Joined: Mon Nov 17, 2008 2:41 pm
Re: get category_id and the id's of it's sub categories
Sorry about that.
I just grabbed that code from a class I wrote a while ago.
I've attached the module I wrote to sort this out. Let me know if you can find anything helpful from this.
You may be able to plug this in and get what you're looking for, or at the very least grab some code that might help.
I just grabbed that code from a class I wrote a while ago.
I've attached the module I wrote to sort this out. Let me know if you can find anything helpful from this.
You may be able to plug this in and get what you're looking for, or at the very least grab some code that might help.
You do not have the required permissions to view the files attached to this post.
- djemmers
- Joomla! Intern
- Posts: 90
- Joined: Thu May 22, 2008 7:09 am
Re: get category_id and the id's of it's sub categories
that is exactly what I am looking for!
tnx
but I keep having the same problem:
Fatal error: Call to a member function get() on a non-object in /home/tornooi/domains/tornooi.net/public_html/joomla160/jumifiles/events.php on line 41
it always is here:
if($params->get('count', 0) > 0 && count($items) > $params->get('count', 0)) {
the $params is empty ...
where is it's value set?
tnx
but I keep having the same problem:
Fatal error: Call to a member function get() on a non-object in /home/tornooi/domains/tornooi.net/public_html/joomla160/jumifiles/events.php on line 41
it always is here:
if($params->get('count', 0) > 0 && count($items) > $params->get('count', 0)) {
the $params is empty ...
where is it's value set?
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
-
- Joomla! Apprentice
- Posts: 31
- Joined: Mon Nov 17, 2008 2:41 pm
Re: get category_id and the id's of it's sub categories
The params are set when you configure the module.
By selecting the number of categories, etc., the params should be set.
By selecting the number of categories, etc., the params should be set.
- djemmers
- Joomla! Intern
- Posts: 90
- Joined: Thu May 22, 2008 7:09 am
Re: get category_id and the id's of it's sub categories
ok, tnx
I'll try to install the module instad of taking bits of the code.
and see where that gets me.
I'll try to install the module instad of taking bits of the code.
and see where that gets me.
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands