Insert banners between category articles

Need help with the Administration of your Joomla! 3.x site? This is the spot for you.

Moderator: General Support Moderators

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 Reply
sylwekb
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 178
Joined: Mon Mar 14, 2011 5:08 pm

Insert banners between category articles

Post by sylwekb » Mon Sep 17, 2018 11:23 am

Hello
How can you insert banners between category articles?
Can this be done with a standard module for placing banners?
You do not have the required permissions to view the files attached to this post.

User avatar
lefteriskavadas
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Fri Feb 05, 2016 6:10 pm
Location: Athens, Greece
Contact:

Re: Insert banners between category articles

Post by lefteriskavadas » Mon Sep 17, 2018 11:42 am

Hi,

Yes, this can be done. Here is the code to render a module position:

Code: Select all

$modules = JModuleHelper::getModules('my_module_position');
foreach ($modules as $module)
{
    echo JModuleHelper::renderModule( $module, array('style' => 'html5'));
}
You can place this inside the articles loop in a layout override of the category page.

Regards

annahersh
Joomla! Explorer
Joomla! Explorer
Posts: 271
Joined: Wed Aug 15, 2018 8:23 pm

Re: Insert banners between category articles

Post by annahersh » Mon Sep 17, 2018 7:27 pm

If your goal is to insert a module at a given item position, like after the 3rd item, it can be done within the intro items loop using the $counter value.

You'll need a template override of components/com_content/views/category/tmpl/blog.php

Find the line that reads

Code: Select all

<?php if (($rowcount == $this->columns) or ($counter == $introcount)) : ?>
    </div><!-- end row -->
<?php endif; ?>
Place the following below the above coding

Code: Select all

<?php if( $counter == 3 ) { ?>
    <div class="inserted-module">
      <?php 
      JPluginHelper::importPlugin('content');
      // parse loadmodule content plugin shortcode with a module titled "bannerads" using template module style xhtml
      echo JHtml::_('content.prepare', '{loadmodule bannerads,xhtml}'); 
      ?>
    </div>
<?php } ?>
Change the number 3 to define where the module will display.

The output will occur for every category so if you need specific categories to have the out put, add a conditional statement to the existing eg:

Code: Select all

$cats = [8,14,12,50];
if( in_array($this->category->id, $cats) && $counter == 3 ) { 


Post Reply

Return to “Administration Joomla! 3.x”