The Joomla! Forum ™



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.



Post new topic Reply to topic  [ 16 posts ] 
Author Message
PostPosted: Fri Jan 28, 2011 8:13 am 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Thu May 22, 2008 7:09 am
Posts: 90
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

_________________
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands


Top
 Profile  
 
PostPosted: Wed Feb 02, 2011 1:15 pm 
Joomla! Explorer
Joomla! Explorer

Joined: Mon Dec 15, 2008 11:10 am
Posts: 337
Me to want to know this...

Anybody that can help?


Top
 Profile  
 
PostPosted: Thu Feb 03, 2011 11:04 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jan 21, 2011 3:02 pm
Posts: 16
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:

Code:
$catID = JRequest::getVar('id')


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:
Code:
$view = JRequest::getVar('view');


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


Top
 Profile  
 
PostPosted: Thu Feb 03, 2011 1:51 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Thu May 22, 2008 7:09 am
Posts: 90
tnx for the reply,
but I can't seem to get the child categories...

I tried

Code:
jimport( 'joomla.application.categories' );
$catID = JRequest::getVar('id');
echo $catID."<br/>";
print_r(get($catID));

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?

_________________
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands


Top
 Profile  
 
PostPosted: Thu Feb 03, 2011 2:15 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jan 21, 2011 3:02 pm
Posts: 16
Try JCategories::get($catID)


Top
 Profile  
 
PostPosted: Thu Feb 03, 2011 2:29 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Thu May 22, 2008 7:09 am
Posts: 90
Code:
$catID = JRequest::getVar('id');
echo $catID;
$test=JCategories::get($catID);
print_r($test);

gives

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:
$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


Top
 Profile  
 
PostPosted: Thu Feb 03, 2011 2:50 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Thu May 22, 2008 7:09 am
Posts: 90
I tried:
Code:
$catID = JRequest::getVar('id');
echo $catID;
$test= & JCategories::get($catID);
print_r($test);

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

_________________
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands


Top
 Profile  
 
PostPosted: Thu Feb 03, 2011 3:07 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jan 21, 2011 3:02 pm
Posts: 16
jimport('joomla.application.categories');
$categories = new JCategories('com_content');
$subCategories = $categories->get($catID);

that worked for me, where 'com_content' is the extension

*updated*


Top
 Profile  
 
PostPosted: Fri Feb 04, 2011 8:39 am 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Thu May 22, 2008 7:09 am
Posts: 90
ok, now the error is gone but I can't get the subcategories.
Code:
$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);

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?

_________________
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands


Top
 Profile  
 
PostPosted: Mon Feb 14, 2011 12:58 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Thu May 22, 2008 7:09 am
Posts: 90
I also posted this in a dutch forum
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


Top
 Profile  
 
PostPosted: Wed Apr 20, 2011 12:53 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Nov 17, 2008 2:41 pm
Posts: 31
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...

Code:
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:
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;
   }


Top
 Profile  
 
PostPosted: Wed Apr 20, 2011 7:34 am 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Thu May 22, 2008 7:09 am
Posts: 90
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:
Code:
$category = $categories->get(modArticleSubcategoriesHelper::getArticleCategory($article_id));


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:
Code:
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 ) )


anny suggestions?

_________________
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands


Top
 Profile  
 
PostPosted: Wed Apr 20, 2011 2:59 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Nov 17, 2008 2:41 pm
Posts: 31
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.


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
PostPosted: Fri Apr 22, 2011 9:20 am 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Thu May 22, 2008 7:09 am
Posts: 90
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?

_________________
One fine day I'll be a Joomla 'expert' !
Tornooi.net : Sports database (tournaments and camps) for Belgium and the Netherlands


Top
 Profile  
 
PostPosted: Fri Apr 22, 2011 2:28 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Nov 17, 2008 2:41 pm
Posts: 31
The params are set when you configure the module.
By selecting the number of categories, etc., the params should be set.


Top
 Profile  
 
PostPosted: Tue Apr 26, 2011 8:04 am 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Thu May 22, 2008 7:09 am
Posts: 90
ok, tnx

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ] 



Who is online

Users browsing this forum: astarmaths, strumjan, Yahoo [Bot] and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group