Is it possible to display categories in an automatically generated dropdown list? Ideally, I'd have four different parent categories, each with 10 - 15 children categories (in 4 different dropdowns). When a category is clicked in a drop down, it would display the contents in that category in a blog layout.
I'm open to any ideas or suggestions.
Display Categories in a Dropdown?
Moderator: General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
- numinousmedia
- Joomla! Ace
- Posts: 1567
- Joined: Fri Dec 16, 2011 6:13 pm
- Location: Barberton, OH
- Contact:
Display Categories in a Dropdown?
Ryan
Frontend Developer and Joomla Professional
Ethode Website Development: http://www.ethode.com
Personal Site: http://www.numinousmedia.com
Frontend Developer and Joomla Professional
Ethode Website Development: http://www.ethode.com
Personal Site: http://www.numinousmedia.com
- FidelGonzales
- Joomla! Guru
- Posts: 584
- Joined: Thu Nov 03, 2005 12:10 am
- Location: Hesperia, California, USA
- Contact:
Re: Display Categories in a Dropdown?
I would assume there are multiple modules that can accomplish this via the Joomla Extensions Directory. Since Joomla 1.0, I have not dealt with Joomla Content Component and would recommend considering the K2 component, as there are multiple standard and advanced modules and plugins that enable you to accomplish this.
http://www.MediaArmory.com - WEB | PHOTO | WRITE | MARKETING | DESIGN
http://www.DirtArmory.com - Off Road Sports Lifestyle
http://www.DirtArmory.com - Off Road Sports Lifestyle
- numinousmedia
- Joomla! Ace
- Posts: 1567
- Joined: Fri Dec 16, 2011 6:13 pm
- Location: Barberton, OH
- Contact:
Re: Display Categories in a Dropdown?
Yeah... welp, there really weren't any good extensions that would do this, and only this. I'm definitely not going to tangle with a big component like K2 just to get categories to display in a dropdown field. Fortunately, I did figure out how to tweak one of native Joomla modules to make this happen just about perfectly.
This requires making a small change to one of the core Joomla files... if you aren't comfortable doing this, I would avoid this solution. Otherwise...
How to Display Joomla Categories in a Dropdown Field:
The module of choice is the "Articles Categories" module. Natively, this module displays a list of categories in your website. I was able to adapt this module to display that list as options in a dropdown field instead.
You will need to edit this file: /modules/mod_articles_categories/tmpl/default_items.php
The original code looks like this:
My tweaked code looks like this:
Basically, the list elements are replaced with field elements. There was also the need to change how the link is created to conform to a list style "on-click" route instead of the normal "<a href".
Along with making this tweak to the code, I changed the "Maximum Level Depth" to 1 in the Module Parameters.
Hopefully this helps someone tackle this issue without investing tons of time reading up on it :-)
This requires making a small change to one of the core Joomla files... if you aren't comfortable doing this, I would avoid this solution. Otherwise...
How to Display Joomla Categories in a Dropdown Field:
The module of choice is the "Articles Categories" module. Natively, this module displays a list of categories in your website. I was able to adapt this module to display that list as options in a dropdown field instead.
You will need to edit this file: /modules/mod_articles_categories/tmpl/default_items.php
The original code looks like this:
Code: Select all
<?php
/**
* @package Joomla.Site
* @subpackage mod_articles_categories
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// no direct access
defined('_JEXEC') or die;
foreach ($list as $item) :
?>
<li <?php if ($_SERVER['PHP_SELF'] == JRoute::_(ContentHelperRoute::getCategoryRoute($item->id))) echo ' class="active"';?>> <?php $levelup=$item->level-$startLevel -1; ?>
<h<?php echo $params->get('item_heading')+ $levelup; ?>>
<a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($item->id)); ?>">
<?php echo $item->title;?></a>
</h<?php echo $params->get('item_heading')+ $levelup; ?>>
<?php
if($params->get('show_description', 0))
{
echo JHtml::_('content.prepare', $item->description, $item->getParams(), 'mod_articles_categories.content');
}
if($params->get('show_children', 0) && (($params->get('maxlevel', 0) == 0) || ($params->get('maxlevel') >= ($item->level - $startLevel))) && count($item->getChildren()))
{
echo '<ul>';
$temp = $list;
$list = $item->getChildren();
require JModuleHelper::getLayoutPath('mod_articles_categories', $params->get('layout', 'default').'_items');
$list = $temp;
echo '</ul>';
}
?>
</li>
<?php endforeach; ?>
Code: Select all
<select>
<?php
/**
* @package Joomla.Site
* @subpackage mod_articles_categories
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// no direct access
defined('_JEXEC') or die;
foreach ($list as $item) :
?>
<option onclick="window.location = '<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($item->id)); ?>'" <?php if ($_SERVER['PHP_SELF'] == JRoute::_(ContentHelperRoute::getCategoryRoute($item->id))) echo ' class="active"';?>> <?php $levelup=$item->level-$startLevel -1; ?>
<h<?php echo $params->get('item_heading')+ $levelup; ?>>
<?php echo $item->title;?>
</h<?php echo $params->get('item_heading')+ $levelup; ?>>
<?php
if($params->get('show_description', 0))
{
echo JHtml::_('content.prepare', $item->description, $item->getParams(), 'mod_articles_categories.content');
}
if($params->get('show_children', 0) && (($params->get('maxlevel', 0) == 0) || ($params->get('maxlevel') >= ($item->level - $startLevel))) && count($item->getChildren()))
{
echo '<ul>';
$temp = $list;
$list = $item->getChildren();
require JModuleHelper::getLayoutPath('mod_articles_categories', $params->get('layout', 'default').'_items');
$list = $temp;
echo '</ul>';
}
?>
</option>
<?php endforeach; ?>
</select>
Along with making this tweak to the code, I changed the "Maximum Level Depth" to 1 in the Module Parameters.
Hopefully this helps someone tackle this issue without investing tons of time reading up on it :-)
Ryan
Frontend Developer and Joomla Professional
Ethode Website Development: http://www.ethode.com
Personal Site: http://www.numinousmedia.com
Frontend Developer and Joomla Professional
Ethode Website Development: http://www.ethode.com
Personal Site: http://www.numinousmedia.com
- FidelGonzales
- Joomla! Guru
- Posts: 584
- Joined: Thu Nov 03, 2005 12:10 am
- Location: Hesperia, California, USA
- Contact:
Re: Display Categories in a Dropdown?
Excellent. Thanks for adding your solution.
http://www.MediaArmory.com - WEB | PHOTO | WRITE | MARKETING | DESIGN
http://www.DirtArmory.com - Off Road Sports Lifestyle
http://www.DirtArmory.com - Off Road Sports Lifestyle
-
- Joomla! Intern
- Posts: 88
- Joined: Wed Nov 30, 2016 5:02 pm
- Location: South Africa
Re: Display Categories in a Dropdown?
Thanks for the solution!numinousmedia wrote:You will need to edit this file: /modules/mod_articles_categories/tmpl/default_items.php
BUT, is it possible to make these changes without editing the Joomla core file? Maybe an override? Or, creating another file applicable to the specific "Articles Categories"-module only?
I enjoy building websites on an ad-hoc charitable basis.
-
- Joomla! Intern
- Posts: 88
- Joined: Wed Nov 30, 2016 5:02 pm
- Location: South Africa
Re: Display Categories in a Dropdown?
Solution: Template override... (answering my own question, if someone ever have similar question)
Within Joomla; Extensions -> Templates -> Templates -> 'select your template' -> Create Overrides -> 'select e.g. applicable module'. Make changes to this file, thus not editing any Joomla core file(s).
Within Joomla; Extensions -> Templates -> Templates -> 'select your template' -> Create Overrides -> 'select e.g. applicable module'. Make changes to this file, thus not editing any Joomla core file(s).
I enjoy building websites on an ad-hoc charitable basis.