Grouping Adjustment for mod_articles_category

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
FTAdmin
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Tue Mar 25, 2014 1:56 pm

Grouping Adjustment for mod_articles_category

Post by FTAdmin » Tue Mar 25, 2014 3:10 pm

Currently mod_articles_category is capable of grouping articles by category and also linking the category title at the end of the article.

Example of Current Output:
*
* Article 1 (Category 1)
* Article 2 (Category 1)
*
* Article 3 (Category 2)
* Article 4 (Category 2)

I made a template override to this module that places the category title at the beginning of each group. The title retains its link.

Example of Override Output:
* Category 1
* Article 1
* Article 2
* Category 2
* Article 3
* Article 4

Simply put, the code chunk for placing (linked) category titles was moved to the LI of each first level UL, and then a variable and a WHILE statement were used to limit the output iterations created by the FOREACH statement that outputs the titles (with links) from $group as $item.

There is likely a smarter way of outputting linked titles, but I'm not savvy enough to figure out how to grab the category title element (only once) of $group as $item without using FOREACH.

FYI: There is a very simple one-line code chunk to make the titles display, by echoing $group_name, but then the category titles aren't linked.

Old Code (starting at line 16 [as of Joomla! v3.2.3])

Code: Select all

	<li>
		<ul>
			<?php foreach ($group as $item) : ?>
				<li>
					<?php if ($params->get('link_titles') == 1) : ?>
						<a class="mod-articles-category-title <?php echo $item->active; ?>" href="<?php echo $item->link; ?>">
						<?php echo $item->title; ?>
						</a>
					<?php else : ?>
						<?php echo $item->title; ?>
					<?php endif; ?>

					<?php if ($item->displayHits) : ?>
						<span class="mod-articles-category-hits">
						(<?php echo $item->displayHits; ?>)
						</span>
					<?php endif; ?>

					<?php if ($params->get('show_author')) :?>
						<span class="mod-articles-category-writtenby">
						<?php echo $item->displayAuthorName; ?>
						</span>
					<?php endif;?>

					<?php if ($item->displayCategoryTitle) :?>
						<span class="mod-articles-category-category">
						(<?php echo $item->displayCategoryTitle; ?>)
						</span>
					<?php endif; ?>
New Code (old code left in place, commented out, for reference)

Code: Select all

	<li>
		<?php $printgroupname="allow"; #limiter variable. actual value is moot, so long as it matches the following WHILE statement ?>
		<?php foreach ($group as $item) : #start original category name code block ?>
			<?php while ($printgroupname=="allow") : #interject an artificial limiter on $item iteration ?>
				<?php if ($item->displayCategoryTitle) : ?>
					<span class="mod-articles-category-category">
					<?php echo $item->displayCategoryTitle; ?>
					</span>
				<?php endif; ?>
				<?php $printgroupname="disallow"; #make the WHILE statement invalid, so as to prevent further $item iteration ?>
			<?php endwhile; ?>
		<?php endforeach; ?>
		
		<ul>
			<?php foreach ($group as $item) : ?>
				<li>
					<?php if ($params->get('link_titles') == 1) : ?>
						<a class="mod-articles-category-title <?php echo $item->active; ?>" href="<?php echo $item->link; ?>">
						<?php echo $item->title; ?>
						</a>
					<?php else : ?>
						<?php echo $item->title; ?>
					<?php endif; ?>

					<?php if ($item->displayHits) : ?>
						<span class="mod-articles-category-hits">
						(<?php echo $item->displayHits; ?>)
						</span>
					<?php endif; ?>

					<?php if ($params->get('show_author')) :?>
						<span class="mod-articles-category-writtenby">
						<?php echo $item->displayAuthorName; ?>
						</span>
					<?php endif;?>

					<!--ORIGINAL CODE FOR CATEGORY TITLES-->
					<?php /*foreach ($group as $item) : ?>
						<?php if ($item->displayCategoryTitle) :?>
							<span class="mod-articles-category-category">
							<?php echo $item->displayCategoryTitle; ?>
							</span>
						<?php endif; ?>
					<?php endforeach;*/ ?>

crly
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Sun Nov 23, 2008 1:01 am

Re: Grouping Adjustment for mod_articles_category

Post by crly » Fri Jan 09, 2015 10:12 am

Thank you! This is much better, and is how I expected the original module to behave.
Thanks again!
Carly


Locked

Return to “Joomla! 3.x Coding”