Hi, I am messing around with the com_content/view/article component in joomla 2.5
I am trying to add all subdirectories to the class for view.html.php, I can't seem to get the information out of the database. I've been successful at getting The article category and parent category. I tried editing model/article.php I added a loop that would query->select and query->join but I was not sure how to check if the database had more subcategories.
The model gets the article info. uses catID to join the category, then it joins the subcategory and that's it. I want to try and loop through until each subcategory loaded has 0 or null as their parent_id.
The reason why I am doing this is because I want to have opengraph information for each category. In my view.html.php I have a code that sets opengraph description to the article, if there is none in database, it goes to category, if there is none there it loads it from the menu, (not sure if I have that working properly yet), if not then from configuration.php. Well I would like to add in their before menu, subcategories.
Any one have any ideas?
Load subcatagory information into object in com_content
Moderator: ooffick
Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
-
- Joomla! Apprentice
- Posts: 20
- Joined: Fri Jan 30, 2015 6:01 am
Load subcatagory information into object in com_content
Last edited by toivo on Sun Feb 21, 2016 9:13 am, edited 2 times in total.
Reason: mod note: moved to 2.5 Coding
Reason: mod note: moved to 2.5 Coding
- toivo
- Joomla! Master
- Posts: 17439
- Joined: Thu Feb 15, 2007 5:48 am
- Location: Sydney, Australia
Re: Load subcatagory information into object in com_content
Each subcategory has a parent, the category above in the tree.I want to try and loop through until each subcategory loaded has 0 or null as their parent_id.
The function _countItemsInChildren() in plugins/content/joomla/joomla.php shows how to process all subcategories of a category. It uses the method getTree(), defined in libraries/joomla/table/nested.php.
BTW, modifying core code is not a good idea. There are other ways like overriding views in the html folder of your template and content plugins, which allow you to do almost everything to articles and forms at different stages.
Toivo Talikka, Global Moderator
-
- Joomla! Apprentice
- Posts: 20
- Joined: Fri Jan 30, 2015 6:01 am
Re: Load subcatagory information into object in com_content
Thank you so much for your reply! Very happpy.
This is a good lead I am going to look into it!
Also I have a plugin which overrides all the files.
The module files, the view.html.php files and for now regular template overrides for tmpl/default.php and so on!
This is a good lead I am going to look into it!
Also I have a plugin which overrides all the files.
The module files, the view.html.php files and for now regular template overrides for tmpl/default.php and so on!
-
- Joomla! Apprentice
- Posts: 20
- Joined: Fri Jan 30, 2015 6:01 am
Re: Load subcatagory information into object in com_content
now this checker a category, but what if I want to work backwards.
News > Web news > Functionality | And find all the parents of functionality.
> Global News > France | but not show all the categories of news.
Is there a build in function for that,
also I couldn't get this to work.
jimport('joomla.database.table');
jimport('joomla.database.tablenested');
print_r( JTableNested::getTree('43'));
News > Web news > Functionality | And find all the parents of functionality.
> Global News > France | but not show all the categories of news.
Is there a build in function for that,
also I couldn't get this to work.
jimport('joomla.database.table');
jimport('joomla.database.tablenested');
print_r( JTableNested::getTree('43'));
Code: Select all
[21-Feb-2016 12:52:58 America/New_York] PHP Notice: Undefined property: ContentViewArticle::$_tbl_key in /libraries/joomla/database/tablenested.php on line 171
[21-Feb-2016 12:52:58 America/New_York] PHP Notice: Undefined property: ContentViewArticle::$_db in /libraries/joomla/database/tablenested.php on line 175
[21-Feb-2016 12:52:58 America/New_York] PHP Fatal error: Call to a member function getQuery() on a non-object in /libraries/joomla/database/tablenested.php on line 175
-
- Joomla! Apprentice
- Posts: 20
- Joined: Fri Jan 30, 2015 6:01 am
Re: Load subcatagory information into object in com_content
I tried this code but i get errores
where this was
$db->setQuery($query);
$data= $db->loadObject();
I get errors still
Code: Select all
$db - > setQuery($query);
$datafinal = $db - > loadObject();
$query2 = $db - > getQuery(true);
$query2 - > select('parent.id AS parent0_id, parent.parent_id AS parent_parent0_id, parent.metadesc AS parent0_metadesc');
$query2 - > from('#__content AS a');
$query2 - > join('LEFT', '#__categories AS parent ON parent.id = a.catid');
$db - > setQuery($query2);
$datafinal = (object) array_merge((array) $db - > loadObject(), (array) $datafinal);
for ($i = 1; $i > 0; $i++) {
$query2 = $db - > getQuery(true);
$query2 - > select('parent.id AS parent'.$i.
'_id, parent.parent_id AS parent_parent'.$i.
'_id, parent.metadesc AS parent'.$i.
'_metadesc');
$query2 - > from('#__categories AS parent WHERE parent'.$i.
'.id = parent_parent'.($i - 1).
'_id');
$db - > setQuery($query2);
$datafinal = (object) array_merge((array) $db - > loadObject(), (array) $datafinal);
}
$db->setQuery($query);
$data= $db->loadObject();
I get errors still