Page selection

griffinmt
griffinmt's picture

Joined: 2009-09-06
Posts: 128
Posted: Sat, 2009-09-19 16:34

Not sure if this has already been covered, so forgive me if it is 'old stuff'.

When navigating through any large sized albums, it would be nice to have more than just the First, Last, Next and Previous buttons to select on the thumbnails. In addition, it would be usefull to have a dropdown list of page numbers to allow you to select how far into an album you can jump. This is especially usefull when moving around from album to album as it would allow immediate movement down to a previous page that was being looked at.

Would also be nice to display this on the thumbnail page as something like 'Page xx of yy'.

Martyn T. Griffin

Login or register to post comments
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 11018
Posted: Mon, 2009-09-21 23:36

I haven't seen anyone post anything about this. This could easily be a specific theme modification. I'm not sure of the modification you'd make, but /themes/YourTheme/views/pager.html.php is where you'd make the change.

Quote:
Would also be nice to display this on the thumbnail page as something like 'Page xx of yy'.

Should be easy to calculate the number of pages since you know where you're at
%from_number

and the total number on that page
%to_number minus %from_number plus 1

and the total count
%count

     $from_to_msg = t2("Photo %from_number of %count",
                       "Photos %from_number - %to_number of %count",
                       $total_items,
                       array("from_number" => $current_first_item,
                             "to_number" => $current_last_item,
                             "count" => $total_items)) ?>

____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

Login or register to post comments
griffinmt
griffinmt's picture

Joined: 2009-09-06
Posts: 128
Posted: Tue, 2009-09-22 04:37

Ok, thanks for the starting point. Is there a variable that represents either the # pics per page or the highest page number. $last_page seems to be blank?!
The problem occurs on the last page when it is not a full page, %to_number minus %from_number plus 1 does not work.

OK, $last_page has the correct last page number except for when you are on the last page, then it is empty and is used as the switch to prevent the Next and Last buttons from being shown!!

Can I add session variables at this point? I would save the $last_page value if this is the first page and when $last_page is empty, I could just pull it from the session.

Martyn T. Griffin

Login or register to post comments
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 11018
Posted: Tue, 2009-09-22 10:40

http://docs.kohanaphp.com/libraries/pagination

Unfortunately, not being a programmer myself, I tried messing around with that and couldn't get anywhere. I'd need some hand-holding to learn how that works.

Not sure why you want to save any data to the session.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

Login or register to post comments
griffinmt
griffinmt's picture

Joined: 2009-09-06
Posts: 128
Posted: Tue, 2009-09-22 14:55

On the first page that is displayed, I want to save the number of the LAST page, because when the actual last page is shown, that page number is not actually available from any of the variables.
The following two images might show what I mean.
Image one is using information available in the supplied variables. Image two is is using the information available on the last page.
I was also planning on adding a dropdown list of all available page numbers so the user can navigate DIRECTLY to a specific page.

This is the rough code in pager.html.php to add this.

Quote:
if (($first_page > 0) and ($last_page > 0))
{
$page_size = $current_last_item - $current_first_item + 1;
$this_page_no = intval(($current_last_item + $page_size -1) / $page_size);
$last_page_no = intval(($total_items + $page_size -1) / $page_size);
}
if (($first_page < 1) and ($last_page > 0))
{
$this_page_no = 1;
$last_page_no = $last_page;
$page_size = $current_last_item - $current_first_item + 1;
$_SESSION['MYLAST'] = $last_page; //*********//
}
if ((first_page > 0) and ($last_page < 1))
{
$last_page_no = $_SESSION['MYLAST']; //*********//
$this_page_no = $last_page_no;
}
if (($first_page < 1) and ($last_page < 1))
{
$this_page_no = 1;
$last_page_no = 1;
}

Martyn T. Griffin

AttachmentSize
Two.jpg11.85 KB
One.jpg14.7 KB
Login or register to post comments
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 11018
Posted: Tue, 2009-09-22 15:19

http://docs.kohanaphp.com/libraries/pagination

<? echo($current_page); ?>

<? echo($total_pages); ?>

____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

Login or register to post comments
griffinmt
griffinmt's picture

Joined: 2009-09-06
Posts: 128
Posted: Tue, 2009-09-22 16:19

BINGO!

Those are the two (and only) values I really needed.

So tell me, if you are not a php programmer, just where do you find this info???

:) And this just begs the next question - how does one create a drop down list with the same look and feel of the other buttons - just point me and I will try to work it out.

Thanks,
Martyn T. Griffin

Login or register to post comments
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 11018
Posted: Tue, 2009-09-22 16:51

trial and error, trial and error Plus I read the second line in pager.html.php that point to the Kohana docs, then read those (closer the 2nd time around) :)

I don't know about the same look and feel, that would be styling and I'm even worse there. www.google.com is my CSS reference :)

As for a drop down list, since you know the total number of pages it should be easy to either do a loop or something like that to populate a <select> tag with the correct data to create a drop down.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

Login or register to post comments
griffinmt
griffinmt's picture

Joined: 2009-09-06
Posts: 128
Posted: Tue, 2009-09-22 17:10

That link is well worth saving!

And now I have taken a quick look, making alterations would seem to be a whole lot more straight forward than originally thought!

Thanks again,
Martyn T. Griffin

Login or register to post comments
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 11018
Posted: Tue, 2009-09-22 17:22

Yeah, customizing G3 is going to be sooo much easier and nicer than G2. :)
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

Login or register to post comments
markmac

Joined: 2009-10-14
Posts: 12
Posted: Wed, 2009-10-14 16:57

Can someone post the complete code that needs to go into pager.html.php? I am a noobian to PHP and my skills are limited. I tried implementing some of what is above, but can't seem to figure it out. I am interested in getting the page numbers like griffinmt has on his site.

Thanks for any help!

Login or register to post comments
griffinmt
griffinmt's picture

Joined: 2009-09-06
Posts: 128
Posted: Thu, 2009-10-15 22:44

This was the code I added to pager.html.php inside MY theme, just before the line
<li class="g-txt-right">

Quote:
<!-- Add paging info -->
<li>
<!--
At this point, if there are more than 2 pages to show, lets create a page selection list
to speed up navigation when moving stuff around.
-->
<?
if ($total_pages > 2)
{
echo "<div class='g-page-list'><center>Page <select onchange='if (this.selectedIndex > 0) document.location.href=this.value;'>\n";
for ($i=1;$i<=$total_pages;$i++)
{
if ($i == $current_page)
{
echo "<option value='".str_replace('{page}',$i,$url)."' selected>$i</option>\n";
}
else
{
echo "<option value='".str_replace('{page}',$i,$url)."'>$i</option>\n";
}
}
echo "</select></center></div>";
}
else
{
echo $from_to_msg;
}
?>
</li>

Also in the css file I added this after the definition for
#g-content #g-album-grid {

Quote:
.g-page-list {
margin: 1px;
width: 120%;
text-align: center;
font-size: 1em;
font-weight: 900;
color: #4868e8;
position: relative;
top: -20px;
display: inline;
}
.g-page-list select {
margin: 1px;
text-align: center;
font-size: .9em;
font-weight: 900;
color: #4868e8;
display: inline;
}

The above 'evolved' so there is some redundancy in the css. Will thin it out when I have a chance.

This results in the appearance attached.
Martyn T. Griffin

AttachmentSize
page2.jpg25.59 KB
Login or register to post comments
markmac

Joined: 2009-10-14
Posts: 12
Posted: Fri, 2009-10-16 16:24

Thank you thank you thank you Martyn! Worked like a charm!

Login or register to post comments
markmac

Joined: 2009-10-14
Posts: 12
Posted: Fri, 2009-10-16 17:03

Just one other question,

I put this code in the pager.html.php file, and it puts the page number selection at the bottom of the page. No matter how far in that pager file I put it (it is currently at the top) it still shows it at the bottom. I would also like to have it show at the top, just under my album title. Where would I put that code in? I am currently using the default theme.

Thanks again for your help! Great resource

Login or register to post comments
griffinmt
griffinmt's picture

Joined: 2009-09-06
Posts: 128
Posted: Fri, 2009-10-16 17:51

In album.html.php, locate the line:

Quote:
<?= $theme->pager() ?>

at the bottom and move it up to the top right after the line:

Quote:
<div class="g-description"><?= nl2br(html::purify($item->description)) ?></div>

In dynamic.html.php, locate that same line at the bottom and move it up to just before the line:

Quote:
<ul id="g-album-grid">

Martyn T. Griffin

Login or register to post comments
markmac

Joined: 2009-10-14
Posts: 12
Posted: Fri, 2009-10-16 19:58

Once again Martyn, I am in your debt... Thank you very much! Looks great now!

Login or register to post comments
vallu

Joined: 2009-06-04
Posts: 14
Posted: Fri, 2010-01-15 14:24
griffinmt wrote:
This was the code I added to pager.html.php inside MY theme, just before the line
<li class="g-txt-right">

Quote:
<!-- Add paging info -->
<li>
<!--
At this point, if there are more than 2 pages to show, lets create a page selection list
to speed up navigation when moving stuff around.
-->
<?
if ($total_pages > 2)
{
echo "<div class='g-page-list'><center>Page <select onchange='if (this.selectedIndex > 0) document.location.href=this.value;'>\n";
for ($i=1;$i<=$total_pages;$i++)
{
if ($i == $current_page)
{
echo "<option value='".str_replace('{page}',$i,$url)."' selected>$i</option>\n";
}
else
{
echo "<option value='".str_replace('{page}',$i,$url)."'>$i</option>\n";
}
}
echo "</select></center></div>";
}
else
{
echo $from_to_msg;
}
?>
</li>

I think this is great, but what do I need to change to make this to work with the latest git version of the Gallery 3? There is not anymore pager.html.php now there is paginatior.html.php and this page selector doesn't work with it.

Thanks!

Login or register to post comments