Gallery thumbnails pagination problem
Posted: 01 January 2009 09:20 PM   [ Ignore ]  
Summer Student
Total Posts:  14
Joined  12-16-2008

Moderator’s note: Moved to Howto.

Hello, I am having a problem making the pagination in my gallery work as intended.. Now I have managed to get a half working solution but I would like something better if possible.

I used the gallery template solution from http://www.5pieces.com/blog/alternative-gallery-template/
that uses categories as albums on the index page and then has another template for the thumbnails and the big photo in one place.

but since I really wanted to have pagination for my thumbnails I had to resort to the following solution:

{exp:gallery:entries gallery="{gallery_name}" orderby="date" sort="asc" dynamic="off" category="{segment_4}" limit="20"}
<h2>{category}</h2>
{centries}
{row}

{if segment_5
==''}
<a href="{id_path={gallery_template}/category/}{category_id}/#photosmain" title="{title}"><img src="{thumb_url}" width="{thumb_width}" height="{thumb_height}" alt="{title}"/></a>
{/if}
{if segment_5
=='P0'}
<a href="{id_path={gallery_template}/category/}{category_id}/P0#photosmain" title="{title}"><img src="{thumb_url}" width="{thumb_width}" height="{thumb_height}" alt="{title}"/></a>
{/if}
{if segment_5
=='P20'}
<a href="{id_path={gallery_template}/category/}{category_id}/P21#photosmain" title="{title}"><img src="{thumb_url}" width="{thumb_width}" height="{thumb_height}" alt="{title}"/></a>
{/if}

{
/row}
{
/entries}

{paginate}
<p>Page {current_page} of {total_pages} pages {pagination_links}</p>
{/paginate}
{
/exp:gallery:entries}

so what it does now is checks for the url segment and then supplies the link, since I will most likely never have more than around 40 photos for one gallery this does work, but I was hoping a more flexible solution could be made. The same thing is done for the next and previous entries right below the thumbnails. Here is the code for it:

{exp:gallery:entries gallery="{gallery_name}" dynamic="on" limit="1" log_views="off"}
        
<h1>
{exp:gallery:prev_entry gallery="{gallery_name}"}

{if segment_5
==''}
<a href="{path={gallery_template}/category/}{category_id}#photosmain"><img src="/images/continue3.gif" alt=""/></a>
{/if}
{if segment_5
=='P0'}
<a href="{path={gallery_template}/category/}{category_id}/P0#photosmain"><img src="/images/continue3.gif" alt=""/></a>
{/if}
{if segment_5
=='P21'}
<a href="{path={gallery_template}/category/}{category_id}/P21#photosmain"><img src="/images/continue3.gif" alt=""/></a>
{/if}

{
/exp:gallery:prev_entry}

{title}

{exp
:gallery:next_entry gallery="{gallery_name}"}

{if segment_5
==''}
<a href="{path={gallery_template}/category/}{category_id}#photosmain"><img src="/images/continue4.gif" alt=""/></a>
{/if}
{if segment_5
=='P0'}
<a href="{path={gallery_template}/category/}{category_id}/P0#photosmain"><img src="/images/continue4.gif" alt=""/></a>
{/if}
{if segment_5
=='P21'}
<a href="{path={gallery_template}/category/}{category_id}/P21#photosmain"><img src="/images/continue4.gif" alt=""/></a>
{/if}

{
/exp:gallery:next_entry}

</h1>

<
div class="clear"><img src="{image_url}" width="{width}" height="{height}" alt="{title}" id="photo" class="slicka4" /></div>
<
div class="clear">{if caption}<p>{caption}</p>{/if}</div>
<
div class="photosdetails">
<
span>Date added: {entry_date format="%d/%m/%Y"}</span>
<
span>Camera model: {custom_field_two}</span>
<
span>This image has been viewed {views} {if views == 1}time{/if}{if views != 1}times{/if}</span>
</
div>
</
div>
{/exp:gallery:entries}

I am also wondering why the page number is 20 instead of 1 or 2 or 3…does the gallery module make the page number depending on the limit of entries per page because that what it seems to be doing now. if I limit my entries to say 15 then I have to update the if segment parts to reflect that as well. So all of this works…but I am wondering why the code has to be so messy to achieve such a simple task. Maybe I am missing out on something?

And last but not least, I would like it that there is no previous entry link on the first photo in the gallery as well as there not being a next entry link on the last photo. I have it working properly in weblogs so I’m not really sure why the gallery doesn’t have a start and end but rather just starts from the beginning when you get to the end and vice versa.

I hope this isn’t too complicated for you to figure out. This is my last problem before I can finally put my site online grin

ps of course there is also the problem that if you’re on the last big picture from the first page of thumbnails and you click on the next entry the thumbnails won’t change to the second page

Profile
 
 
Posted: 02 January 2009 02:16 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  24513
Joined  05-20-2002

The P20 instead of 2 is just how the pagination works- the limit is based on what’s in the url.  It seems a little odd at first, but once you understand it, you tend not to notice.

I’m not dead up on the tutorial you’re working from, so not entirely sure why the category info needs to be in the url for single entry pages.  (Not saying it doesn’t- just seems odd.)  That said- if the way you have it setup, the P is always in segment 5, would doing this work?

<a href="{path={gallery_template}/category/}{category_id}/{segment_5}#photosmain"><img src="/images/continue4.gif" alt=""/></a>

No conditional needed.  If I needed to id the P bit more dynamically, it would be easy to do with some php.  But you’re already assuming seg 5 is pagination info- so if that’s the case, the above would be an easy approach.

Make sense?

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 02 January 2009 03:55 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  14
Joined  12-16-2008

damn, I knew it had to be something simple, thank you very much that works just fine and it reduced the amount of code I have to use substantially

regarding the other bits..

the URL has to be the way it is now, the {path={gallery_template}/category/} is the name of the template file I’m using for the single entry page…also since this gallery uses categories as photo albums and since the thumbnails are listed on the single entry page you have to limit the thumbnails to only a specific category…that’s where the {category_id} thing comes in..I would actually love to reduce the segments if possible, or at least use the title of the category instead of the id

but please tell me is it the default behavior that there is no start or finish when using next and previous entry pagination links? I would love to actually limit that to only the photos on the current page, or even better make it so that when you get to the end of one page and click on the next entry the page will change as well

Profile
 
 
Posted: 02 January 2009 04:12 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  24513
Joined  05-20-2002

wink  Glad that bit helped.

The next/prev issue isn’t as simple.  There isn’t a parameter that allows you to change the behavior.  It wouldn’t be hard to hack- but maintaining a hack is really not desirable.

You might take a look at the Entry linker plugin.  It doesn’t do what you want (it was designed to allow next/prev to operate across categories rather than w/in them).  But- you could likely modify it for personal use- and having it in a plugin rather than core code eliminates the maintanence issues w/hacking.

Really- all you need to do is change the cycle parameter.  In the core code:

$sql = $this->next_prev_query($type, 'cycle');

‘cycle’ makes it cycle. 

$sql = $this->next_prev_query($type);

That change?  Would eliminate the behavior.  (I’m pretty sure- though I didn’t test.)  If it’s in the plugin the same way- removing it would take care of the issue.)

As to the url- I suspect you could use a bit of php to figure out the category of the single entry and handle things that way- rather than passing it via the url.  But given that it currently works, I’m not sure you want to get too deep into the php.  (But there’s always more than one way to go at things- so I suspect it would be doable that way.)

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 02 January 2009 11:04 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  14
Joined  12-16-2008

Ok I think I’ll pass with the hack, it doesn’t seem worth it really…but I do have one more question…I’ve tried switching from using the category id to the category name in the URL. I figured the URL would look nicer if the name of an album from my gallery was up there instead of just a number (the category id number)..

and so I’ve changed all the cat_id variables to cat_name and it worked everywhere except the thumbnails themselves…since of course I’m using category=“segment_4” and segment 4 was the id of the category…I know that you can’t use category names for this since you can have names with spaces, duplicates etc…

but I’m still wondering if there is a way that I can use the category id just to show the thumbnails and make all the hrefs use the name, the code is now:

{exp:gallery:entries gallery="{gallery_name}" orderby="date" sort="asc" dynamic="off" category="{segment_4}"limit="21"}
    
<h2>{category}</h2>
    
{entries}
    {row}
<a href="{id_path={gallery_template}/category/}{cat_name}/{segment_5}#photosmain" title="{title}"><img src="{thumb_url}" width="{thumb_width}" height="{thumb_height}" alt="{title}" class="slicka5"/></a>
    
{/row}
    {
/entries}
{paginate}
<p class="clear">Page {current_page} of {total_pages} pages {pagination_links}</p>
{/paginate}
{
/exp:gallery:entries}

could I perhaps do this with a query? I’m not so good with those but I’m guessing that would be the step…what I need is for the link to a category on the index page to be formed with the category name but get the thumbnails on the single entry page with the category id

oh and just one other small detail…is it possible to use anchor links on comment posting entries so that when someone previews or posts a comment in my gallery the page automatically scrolls down to it?

thanks in advance!

Profile
 
 
Posted: 05 January 2009 10:07 AM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  24513
Joined  05-20-2002

Let’s see- I’m still a wee bit fuzzy on the overall setup.  But- we’re talking single entry pages- right?  With the entry_id in the url?  And in the gallery, entries can only be assigned to one category.  So really- instead of using the category names in the urls (where you run into the space, etc issues)- if you’re on a single entry page, you can figure out the category based on the entry id number.  No need for the category indicator at all.

I’d maybe use php, parsed on input.  Say your id number is in segment 3- so

<?php
global $DB;
$cid = 0;
$result = $DB->query("SELECT cat_id FROM exp_gallery_entries");
if (
$result->num_rows == 1)
{
    $cid
= $result->row['cat_id'];
}
?>

{exp
:gallery:entries gallery="{gallery_name}" orderby="date" sort="asc" dynamic="off" category="<?php echo $cid; ?>"limit="21"}

On the anchor links- I know I’ve done it before for regular comments, but won’t swear it didn’t require some tweaking/extension.  I’d just test it out- tweaking the return.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 05 January 2009 10:55 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  14
Joined  12-16-2008

hmm, let me go over this again, my website is now online so I’m sure it will be a lot easier for you to figure out what I want…go to http://www.dovla.info/gallery/

so for example a URL for a photo in the single entry page looks like this now:
http://www.dovla.info/gallery/category/146/1/P0

gallery being the template group name, category being the template name, 146 the photo, 1 the category id and P0 the page number…

what I would like to do is have my URL look like this for example:

http://www.dovla.info/gallery/category/category_name/146/P0

so use the category name in the URL, preferably before the photo name itself, this method you described above, I’m not quite sure I understand it…you say the id number is in segment 3 yet I’m not sure how the php uses that segment since I want to have the category name in the segment 3 instead of the id..

also would it be possible to somehow suppress the template name in the URL?

And regarding the comment anchors…I’d love to have that on both gallery comments and weblog ones, should I start a new topic for it?

Profile
 
 
Posted: 27 March 2009 08:42 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  199
Joined  11-19-2007

Hi Dovia,

The Gallery Module won’t recognize the category_name on the url. It doesn’t have a category_url_title variable. You need to customize the category page something like this:

* from the Index page, modify the links so the category folder rather than id is on the url. You may need to convert it to lowercase or even use urlencode() to make them suited for the url.
* On the Category page you need to convert the category folder back to its original name and query the database for it’s ID. Then use the cat_id on the gallery:entries tag. Your gallery entries tag will need a dynamic=“off” because you are generating the cat_id and you don’t want it to look for it in the url.

EDIT: Just noticed, Robin Sowell, posted a similar concept a few comments up ↑. Here is how I would do it:

Index Page Link

<a href="{path={gallery_name}/album}{cat_folder}" title="{cat_name}">{cat_name}</a>

Category Page

PHP enabled, parsed input

<?php
global $IN, $DB;

$cat_id = FALSE;

$sql    = "SELECT c.cat_id
           FROM "
.$DB->prefix."gallery_categories AS c
           JOIN "
.$DB->prefix."galleries AS g ON c.gallery_id = g.gallery_id
           WHERE g.gallery_short_name = '"
.$IN->fetch_uri_segment(1)."'
           AND c.cat_folder = '"
.$IN->fetch_uri_segment(3)."'";

$query  = $DB->query($sql);

if (
$query->num_rows != 0) {
    $cat_id
= $query->row['cat_id'];
}

?>

<?php
if ($cat_id): ?>

{exp
:gallery:entries gallery="{segment_1}" category="<?php echo $cat_id; ?>" dynamic="off"}
...
{/exp:gallery:entries}

<?php
else: ?>

We could not find the requested category
.

<?php endif; ?>

I did something similar, I didn’t actually use the cat_name or cat_folder in the url, but I changed it to look how I wanted. May not be exactly what you need but hopefully will give you some insight.

Take a look here:

http://expressionengine.com/wiki/Gallery_Module_Alternative_Templates/

 Signature 

http://www.bbook.com

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 77568 Total Logged-in Users: 44
Total Topics: 101557 Total Anonymous Users: 25
Total Replies: 544401 Total Guests: 258
Total Posts: 645958    
Members ( View Memberlist )
Newest Members:  ColeJLinskitnealsemperjrawhallshiusbozzlynobluffkatiejameshsmith101dddougal