将 link 连接到图像
Connecting a link to an image
我将 MediaWiki 与 Joomla 结合使用。因为我想向某些链接添加图标,所以我需要将两者连接起来。我知道这可以通过将 img 标签放在 a 标签内来实现。
但是 问题是一些链接是通过一个名为 makeListItem 的函数生成的,MediaWiki 不仅仅用于这些链接。现在我的问题是,我能否以某种方式将 img 连接到 a 而无需将其放入 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 class)。
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 );
}
我将 MediaWiki 与 Joomla 结合使用。因为我想向某些链接添加图标,所以我需要将两者连接起来。我知道这可以通过将 img 标签放在 a 标签内来实现。
但是 问题是一些链接是通过一个名为 makeListItem 的函数生成的,MediaWiki 不仅仅用于这些链接。现在我的问题是,我能否以某种方式将 img 连接到 a 而无需将其放入 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 class)。
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 );
}