将链接连接到图像

问题描述:

我将MediaWiki与Joomla结合使用。由于我想将图标添加到某些链接,因此我需要将两者都连接起来。我知道这可以通过将img标签放入标签中。将链接连接到图像

但是问题在于一些链接是由一个名为makeListItem的函数生成的,MediaWiki使用的函数不仅仅是这些链接。现在我的问题是,我可以以某种方式将img连接到a,而不必将其放入标签中?

这将调用函数来创建的元素:

<?php $this->renderNavigation('PERSONAL'); ?> 

实际功能(缩短):

foreach ($personalTools as $key => $item) { 
    ?> 
    <div class="searchbox" style="clear:both;"> 
    <img src="<?php echo $icon[$key] ?>" alt="p-Icons" class="iconnav"/> 
    <?php 
    echo $this->makeListItem($key, $item); 
    ?> 
    </div> 
<?php 
} 
?> 

图像的src为被声明正上方的一个数组中定义的foreach。

预先感谢

您必须修改makeListItem()函数(BaseTemplate类)。

function makeListItem($key, $item, $options = array()) { 
    if (isset($item['links'])) { 
     $links = array(); 
     foreach ($item['links'] as $linkKey => $link) { 
      $links[] = $this->makeLink($linkKey, $link, $options); 
     } 
     $html = implode(' ', $links); 
    } else { 
     $link = $item; 
     // These keys are used by makeListItem and shouldn't be passed on to the link 
     foreach (array('id', 'class', 'active', 'tag', 'itemtitle') as $k) { 
      unset($link[$k]); 
     } 
     if (isset($item['id']) && !isset($item['single-id'])) { 
      // The id goes on the <li> not on the <a> for single links 
      // but makeSidebarLink still needs to know what id to use when 
      // generating tooltips and accesskeys. 
      $link['single-id'] = $item['id']; 
     } 
     $html = $this->makeLink($key, $link, $options); 
    } 
    $attrs = array(); 
    foreach (array('id', 'class') as $attr) { 
     if (isset($item[$attr])) { 
      $attrs[$attr] = $item[$attr]; 
     } 
    } 
    if (isset($item['active']) && $item['active']) { 
     if (!isset($attrs['class'])) { 
      $attrs['class'] = ''; 
     } 
     $attrs['class'] .= ' active'; 
     $attrs['class'] = trim($attrs['class']); 
    } 
    if (isset($item['itemtitle'])) { 
     $attrs['title'] = $item['itemtitle']; 
    } 
    return Html::rawElement(isset($options['tag']) ? $options['tag'] : 'li', $attrs, $html); 
} 
+0

不错,谢谢。你能告诉我在哪里定义了makeListItem函数吗? – Pfonks

+0

该函数在BaseTemplate类文件中定义。 – Nvan