Maestro J
Maestro J

Reputation: 1

How to implement this php code

So I have this php code in my joomla site (joomla's latest article module) and I'd like to add a bootstrap tooltip to the title of my links. Can someone point me in the right direction as to how I add this script to a php page. Thanks in advance. Here's the script i got from w3schools.

<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();   
});
</script>

and my code which i already have.

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_articles_latest
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
defined('_JEXEC') or die;
?>
<div style="float: left;margin-right: 47px;">

<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) :  ?>
<li itemscope itemtype="http://schema.org/Article">
    <a href="<?php echo $item->link; ?>" data-toggle="tooltip" title="<?php echo $item->title; ?>" itemprop="url"><img src="/images /sound.png" />&nbsp;
        <span itemprop="name">
            <?php echo $item->title; ?>
        </span>
    </a>
</li>
<?php endforeach; ?>
</ul></div>

Upvotes: 0

Views: 109

Answers (1)

Knight Rules
Knight Rules

Reputation: 31

Please enter the following code inside below defined('_JEXEC')

JFactory::getDocument()->addScriptDeclaration('
$(document).ready(function(){
$(\'[data-toggle="tooltip"]\').tooltip();   
});

');

It will include the script into header automatically

Upvotes: 1

Related Questions