user5325844
user5325844

Reputation:

Connecting a link to an image

I am using MediaWiki in combination with Joomla. As I want to add icons to some links I need to connect both. I know that this is possible through putting the img tag inside the a tag.

BUT the problem is that some links are generated throgh a function called makeListItem that MediaWiki uses for more than just these links. Now my question is, can I somehow connect the img to the a without putting it inside the a tag?

This calls the function to create the elements:

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

The actual function (shortened):

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
}
?>

The src of the image is defined in a array that is declared just above the foreach.

Thanks in advance

Upvotes: 0

Views: 60

Answers (1)

Nvan
Nvan

Reputation: 1146

You have to modify your makeListItem() function (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 );
}

Upvotes: 1

Related Questions