Page 1 of 1

Replace previous/next by images

Posted: Sat Apr 09, 2016 12:15 pm
by Tata
How shall be coded the replacement of next/previous word/character by an image?
I have placed images into the template

Code: Select all

                <table width="100%" cellspacing="0" cellpadding="0" border="0">
                    <tr>
                        <td class="previous">
                            <?php echo tag('img src="'.$pth['folder']['templateimages'].'previous.png" alt="'.$tx['navigator']['previous'].'"');?>
                        </td>
                        <td class="top">
                            <a href="#TOP" title="<?php echo $tx['navigator']['top'];?>"><?php echo tag('img src="'.$pth['folder']['templateimages'].'top.png" alt="'.$tx['navigator']['top'].'"');?>
                        </td>
                        <td class="next">
                            <?php echo tag('img src="'.$pth['folder']['templateimages'].'next.png" alt="'.$tx['navigator']['next'].'"');?>
                        </td>
                    </tr>
                </table>
but the alt attribute doesn't work and I don't know how to link the image to next/previous function.

Re: Replace previous/next by images

Posted: Sat Apr 09, 2016 2:44 pm
by cmb
Tata wrote:[…] the alt attribute doesn't work […]
That is supposed to work; you may need to escape special HTML characters, though:

Code: Select all

<?php echo tag('img src="'.$pth['folder']['templateimages'].'previous.png" alt="'.XH_hsc($tx['navigator']['previous']).'"');?>
Tata wrote:and I don't know how to link the image to next/previous function.
Indeed, that's somewhat a problem. Most likely it's best to make a copy of the functions previouspage() and nextpage() and place them directly in the template under another name; adjust these functions and call them instead of previouspage()/nextpage(). (Not ideal, but supposed to work.)

Code: Select all

function tpl_previouspage()
{
    global $tx;

    $index = XH_findPreviousPage();
    if ($index !== false) {
        return a($index, '" rel="prev" alt="' . $tx['navigator']['previous']) . tag('img src="userfiles/images/flags/de.gif"') . '</a>';
    }
}

function tpl_nextpage()
{
    global $tx;

    $index = XH_findNextPage();
    if ($index !== false) {
        return a($index, '" rel="next" alt="' . $tx['navigator']['next']) . tag('img src="userfiles/images/flags/de.gif"') . '</a>';
    }
} 
BTW: using the default supplied language texts as alt text is not correct, in my opinion, because the alt text is supposed to describe the image, but not its function. I would use the default texts as title, and add some descriptive text for the alt attribute.

Re: Replace previous/next by images

Posted: Sat Apr 09, 2016 6:21 pm
by Tata
THX, that's it. However, on 2lang it seems not to work. I tried to change the code by

Code: Select all

function tpl_previouspage()
{
    global $tx; $pth;

    $index = XH_findPreviousPage();
    if ($index !== false) {
        return a($index, '" rel="prev" alt="' . $tx['navigator']['previous']) . tag('img src="'.$pth['folder']['templateimages'].'previous.png" class="prev"') . '</a>';
    }
}

function tpl_nextpage()
{
    global $tx;

    $index = XH_findNextPage();
    if ($index !== false) {
        return a($index, '" rel="next" alt="' . $tx['navigator']['next']) . tag('img src="'.$pth['folder']['templateimages'].'next.png"') . '</a>';
    }
} 
But the previous, next icons are not loaded and in their properties is:
http://localhost:8888/website/previous.png
but there should be
http://localhost:8888/warhol/templates/ ... evious.png

Re: Replace previous/next by images

Posted: Sun Apr 10, 2016 10:42 pm
by Tata
Nun, am Localhost funtioniert es. AN einer Subdomain an meinem Hostserver, aber nicht. Es würde wohl relative URL brauchen, oder?

Re: Replace previous/next by images

Posted: Wed Apr 13, 2016 4:18 am
by Tata
Das habe ich gelösst. Diese Losung funktioniert aber nur für die Hauptsprache. Was soll da erweitert sein, um auch unter 2lang zu funtionieren?

Re: Replace previous/next by images

Posted: Wed Apr 13, 2016 10:37 am
by lck
Scheint ja bereits behoben zu sein :?

Re: Replace previous/next by images

Posted: Wed Apr 13, 2016 1:09 pm
by Tata
Ja. SO funktioniert es auch unter 2lang pages:

Code: Select all

    function tpl_previouspage()
    {
        global $tx, $pth;

        if ($index !== false) {
            return a($index, '" rel="prev" alt="' . $tx['navigator']['previous']) . tag('img src="'.$pth['folder']['userfiles'].'images/previous.png"') . '</a>';
        }
    }

    function tpl_nextpage()
    {
        global $tx, $pth;

        $index = XH_findNextPage();
        if ($index !== false) {
            return a($index, '" rel="next" alt="' . $tx['navigator']['next']) . tag('img src="'.$pth['folder']['userfiles'].'images/next.png"') . '</a>';
        }
    }

Re: Replace previous/next by images

Posted: Sun Apr 17, 2016 5:42 pm
by Tata
Now, while testing the iconized prev/next function, I see that the "next" works fine. But the "prev" returns always to the very first page. What may be the reason?

Re: Replace previous/next by images

Posted: Mon Apr 18, 2016 5:45 am
by Tata
Turning the PC ON this morning, the "prev" icon works as expected 8-)

Re: Replace previous/next by images

Posted: Mon Apr 18, 2016 5:49 pm
by cmb
Tata wrote:Turning the PC ON this morning, the "prev" icon works as expected 8-)
Fine. :)

Maybe OPcache was involved here, also.