Can’t get pagination to work
Posted: 27 May 2008 06:14 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  110
Joined  04-25-2008

Hi there,

I’m having certain issues trying to get pagination to work on my template. I’m sure this is something simple, but I’m not a programmer and haven’t found anything related on the documentation.

I have a template which displays a list of weblog entries (games) and each title links to that particular weblog entry (the individual game) with other related content, all using the same template.

For example:

List of games
Game page

I use conditionals to either display one loop or another depending on if the segment_3 is empty or not.

Here is my code

On the games list, I’ve added the pagination links but when I click on a next page, I get a blank page. I’m sure it’s got something to do with the url segment conditional I’m using, but I have no idea of another way to achieve this

Any help is highly appreciated since I suck at programming. T_T

[Mod edit: moved to Technical Support forum]

Profile
 
 
Posted: 27 May 2008 09:00 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  24513
Joined  05-20-2002

Yep- the problem is your conditional:
{if segment_3 != “”}

When you have a page indicator in there?  You have a segment_3- in which case, it’s not blank.  And the weblog tag being used is:

{exp:weblog:entries weblog=“game” sort=“asc” track_views=“one” url_title=”{segment_3}” limit=“1”}
So on the second page: http://psnow.es/v3/index.php/global/juego/P25/
It tries to pull in an entry with the url title of P25- which doesn’t exist, so you get nothing in there.

Easiest option is to just use two different templates- one for multi-entry pages, one for the single entry ones.  But there are other options- I’ve used php a la:

<?php
global $IN;
$qstring = $IN->QSTR;
$seg2 = '{segment_2}';
$order = '';
if (
$seg2 == '' OR preg_match("#(^|\/)P(\d+)#", $qstring, $match) OR preg_match("#(^|\/)F(\d+)#", $qstring, $fmatch)) {
if (isset($fmatch[0])) { if ($fmatch[0] == 'F1') { $order = "orderby='ave_rating'"; } elseif ($fmatch[0] == 'F2') { $order = "orderby='comment_total'"; } }
?>
{embed
="opinion/multi" order="<?php echo $order; ?>"}
{embed
="global/footer"}
</body>
</
html>

<?php } else { ?>

{embed
="opinion/single"}
{embed
="global/footer_s"}
</body>
</
html>
<?php } ?>

Flipped out embeds based on what’s in a segment- a bit more complicated than what you need, but that’s the basic php approach.  Personally?  I’d just create two templates.  Unless you really have a good reason to funnel both types of page through a single template.

Anyhoo- make sense what’s up?

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 27 May 2008 09:43 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  110
Joined  04-25-2008

Yeah, made sense. Even thought I don’t understand the code you wrote, I do understand what it does.  LOL

The reason why I’m using the same template is to keep a clean URL hierarchy. It’s much cleaner /game/game-title/ then /game/single/game_title. I’m a perfectionist.  oh oh

Anyway…

I was thinking of doing a conditional which displays the first loop when the query matches the Game weblog ID, but then again, the list of Games would have the same weblog ID too, so it would crash.  shut eye

I’m gonna try and implement the code you gave me, and if no luck, well I guess I’m gonna have to go the easy way and use separate templates.

Thanks for your help, and sorry for posting in the wrong place.

Any other ideas are welcome of course.

Profile
 
 
Posted: 27 May 2008 10:05 AM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  24513
Joined  05-20-2002

Heh- yea, that php was used on that site because we wanted the leaner url structure as well.  Should be simple to modify it for your needs- we had an extra custom ‘sort’ indicator Fx that could be in the url to alter the sort order.  But could strip it down:

<?php
global $IN;
$qstring = $IN->QSTR;
$seg2 = '{segment_2}';
if (
$seg2 == '' OR preg_match("#(^|\/)P(\d+)#", $qstring)) { ?>

{embed
="game/multi"}

<?php }
else { ?>

{embed
="game/single"}

<?php } ?>

That’s the gist- checks if it’s empty or if it’s a Px.  Turn php parsing on, parse on input- should work fine.  You don’t have to embed- can put it all on one template.  I just like to embed to keep it a little easier to follow the code.  Adds a wee bit of overhead, but saves me headaches when I have to go back and figure out how it all works.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 27 May 2008 12:21 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  110
Joined  04-25-2008

Whoa…!!! It works perfectly! This is why I need a coder so badly. Simple stuff like this seems so complicated for me.  red face  Although one day I’ll learn PHP, promise! haha

Many thanks for your time, I really appreciate it.

And yeah, I agree about embedding everything. It’s the best way to keep all the code nice and tidy, and avoids repeating stuff again and again. When I started with the design, I just done the whole page on one template, but now I’m separating every module (those boxes of content you see xD) into its own template, and then embedding them all over the site. Got lots of work to do still.

Once again, thanks for everything. smile

Profile
 
 
Posted: 27 May 2008 12:42 PM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  21123
Joined  05-15-2004

Glad Robin got you squared away there.

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
   
 
 
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: 77557 Total Logged-in Users: 55
Total Topics: 101552 Total Anonymous Users: 31
Total Replies: 544387 Total Guests: 282
Total Posts: 645939    
Members ( View Memberlist )