3

I have been searching already for a while on how to show a list of categories that shows also subcategories, something like this:

enter image description here

In this case, the list of contents only shows a subcategory level (or the articles' names in the category), but I would like to possibly show as many subcategories as I like.

I have tried to create a category list or blog, but the output is not what I want:

enter image description here

Basically I have to click on Intro (which is a subcategory of the category Basics set to the menu). What I would like to obtain is a list of the categories' names, with sublists containing lists to subcategories and/or articles, so that I can click and move around.

If this is not possible with the Joomla's core modules, is there some module that allows me to obtain this?

I know I could create a list of links with all sublists of links with the editor manually, but it would be nice if a module could do it for us.

1

There are few solutions:

If you want to get categories tree only

Use Template Overrides to create alternative layout for categories view. In this view use use JCategories to get categories tree. Here is a sample:

$model_categories = JCategories::getInstance('Content');
$root = $model_categories->get('root');
$categories = $root->getChildren();

You can use getChildren() for every category to get its children.

If you want to get categories tree with all its articles

You create all above but collect categories ID's.Then get from database all articles from those categories using collected ID's. Create articles map array where array key will be category id so your array will look like this:

Array(
    CATEGORY1_ID => array(
       1=>YOUR_ARTICLE_OBJECT1,
       2=>YOUR_ARTICLE_OBJECT2,
       3=>YOUR_ARTICLE_OBJECT3
    ),
    CATEGORY2_ID => array(
       1=>YOUR_ARTICLE_OBJECT1,
       2=>YOUR_ARTICLE_OBJECT2,
    )
);

That way you will need only one query to get articles for all categories. Then simply when printing category use articles map.

Conclusion

This solution has downfalls. Your component will still use queries from model you of course don't need (about 2 of them). You can always use some sort of Sitemap component to get the same view but there are not many of those.

1

see link:

https://stackoverflow.com/questions/17988998/joomla-get-subcategories-of-custom-parent-category

$catID = JRequest::getVar('id');
$categories = JCategories::getInstance('Content');
$cat = $categories->get($catID);
$children = $cat->getChildren();
print_r($children);
1

In Joomla 3.x, you could use the Joomla's native Categories module.

Your example shows 3 categories, so I would load three modules from within the article, and configure these modules to display the informaiton you want.

MODULE CONFIGURATION I WOULD DO:

  • Parent Category: Introduccion
  • Category Descriptions: No
  • Show Number of Articles: No
  • Show Subcategories: Yes
  • # First Subcategories: All
  • Maximum Level Depth: 1
  • Menu assignment: only the pages where you need these

CONTENT OF THE ARTICLE CORRESPONDING TO THE PAGE YOU WANT:

{loadposition inarticle-categories1}

{loadposition inarticle-categories2}

{loadposition inarticle-categories3}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.