[Code Sample] Prev / Next image on tab [Code Sample] Prev / Next image on tab
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

[Code Sample] Prev / Next image on tab

Started by djpushplay, October 15, 2006, 12:47:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

djpushplay

Did a quick search and hopefully, this is not a repeat.  Newbie on this board but decided to give back to this great community.  A while back, I saw in the existing 1.4.9 code stubs for "Prev" and "Next" in the image tab so I took a shot at coding it.  So far it seems to work but I'm not positive it's gold.  I'm sure somebody on here will fix it if it's not.

The code will make the tab look like this:
<Prev 1 ... 5 6 7 8 9 10 ... 320 Next>

theme.php

function theme_create_tabs($items, $curr_page, $total_pages, $template)
{
global $CONFIG, $lang_create_tabs;

    $maxTab = $CONFIG['max_tabs'];

    $tabs = sprintf($template['left_text'], $items, $total_pages);
    if (($total_pages == 1))
    return $tabs;

    $tabs .= $template['tab_header'];
   
//start
$prev = $curr_page - 1;
$p = array('{PREV}' => $lang_create_tabs['previous']);
if ($prev < 1)
$tabs .= strtr( sprintf($template['active_prev_tab']), $p);
else
$tabs .= strtr( sprintf($template['inactive_prev_tab'],$prev), $p);
//end

    if ($curr_page == 1) {
        $tabs .= sprintf($template['active_tab'], 1);
    } else {
        $tabs .= sprintf($template['inactive_tab'], 1, 1);
        if ($curr_page - floor($maxTab / 2) >= 2) //
        $tabs .= $template['dotdotdot']; //
    }

    if ($total_pages > $maxTab){
        $start = max(2, $curr_page - floor(($maxTab - 2) / 2));
        $start = min($start, $total_pages - $maxTab + 2);
        $end = $start + $maxTab - 3;
    } else {
        $start = 2;
        $end = $total_pages - 1;
    }

    for ($page = $start; $page <= $end; $page++) {
        if ($page == $curr_page) {
$tabs .= sprintf($template['active_tab'], $page);
        } else {
$tabs .= sprintf($template['inactive_tab'], $page, $page);
        }
    }

    if ($total_pages > 1) {
if ($curr_page == $total_pages) {
$tabs .= sprintf($template['active_tab'], $total_pages);

} else {
if ($curr_page + ($maxTab / 2) <= $total_pages) //
        $tabs .= $template['dotdotdot']; //
$tabs .= sprintf($template['inactive_tab'], $total_pages, $total_pages);
}
    }

//start
$next = $curr_page + 1;
$n = array('{NEXT}' => $lang_create_tabs['next']);
if ($next > $total_pages)
$tabs .= strtr( sprintf($template['active_next_tab']), $n);
else
$tabs .= strtr( sprintf($template['inactive_next_tab'],$next), $n);
//end

    return $tabs . $template['tab_trailer'];
}


And the tab definitions are:

$template_tab_display = array(
'left_text' => '<td align="left" valign="middle" class="tableh1_compact" style="white-space: nowrap"><b>{LEFT_TEXT}</b></td>' . "\n",
    'tab_header' => '',
    'tab_trailer' => '',
    'dotdotdot' => '<td align="center" valign="middle">...</td>',
    'active_tab' => '<td align="center" valign="middle" class="navmenu_active">%d</td>',
    'inactive_tab' => '<td align="center" valign="middle" class="navmenu"><a href="{LINK}"><b>%d</b></a></td>' . "\n",
    'active_prev_tab' => '<td align="center" valign="middle" class="navmenu_active">{PREV}</td>' . "\n",
    'inactive_prev_tab' => '<td align="center" valign="middle" class="navmenu"><a href="{LINK}"><b>{PREV}</b></a></td>' . "\n",
    'active_next_tab' => '<td align="center" valign="middle" class="navmenu_active">{NEXT}</td>' . "\n",
    'inactive_next_tab' => '<td align="center" valign="middle" class="navmenu"><a href="{LINK}"><b>{NEXT}</b></a></td>' . "\n",
);


english.php

$lang_create_tabs = array(
  'previous' => '&lt;Prev', //cpg1.4 //
  'next' => 'Next&gt;', //cpg1.4 //
);


If you're wondering why I removed the comments from the code above, it's because this is a family board and I tend to write odd comments in my code.

If I forgot to include something here, let me know.  I wrote this a while ago so it's not so fresh in my memory anymore.

Also, I moved the navigation tabs to the top instead of the bottom.  This way, a user can keep his/her cursor on the "Next" and keep clicking without having to move the cursor each time.  Less work for the user.

benj_gos

This is really great  :D, thank you!!

1 question.
I always have the dotdotdot, even if the number of pages is same or higher then what's defined as max pages.
example - album has 5 pages i have set to show 10 pages and i see "1 2 3 4 ... 5".
How would i go about making sure that it shows only when it's above the set limit?

Thanks,
Benji

Hein Traag

Added this mod to my CPG. So far so good. It adds a nice set of tabs to the thumbnail screen. Tested with two pages of thumbs.. adding more pictures to see if the same problem arises as benj_gos.

Cheers!
Hein

Gephri

Installed the mod easily enough, but now I don't have the ... in pages with lots of tabs.
For examples 1,2,3,4,5,6,7,8,9,10,324
Should be 1,2,3,4,5,6,7,8,9,10,...324

Can anyone point me towards the code that controls this?

ppFreddy

Got it working on my testserver, nice and easy mod.

Modded a few things so that if you are on page 1, there is no "previous", and if you are on the last page, ther is nog "next"

Only: on the index, if your albums in your categories are tabbed too, the link you get is just "{LINK}"
The numbered ones are correct though.

(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fusers.telenet.be%2Fwelvaert%2Fdump%2Fbleh.JPG&hash=ba8c90f016ace7246401505852824ac8ac2bc911)

skidpics

Awesome Mod!  ONly problem is that it is showing at the bottom of the page, not the top as described in the first post.  What do I change to place it at the top of the thumb view?

-- Skidpics

dke

really great mod! but i have the same problem aswell, the tabs displaying at the bottom insted of the top left corner, would be sweet not having to move the cursor :) anyway great mod thanks!