• Welcome to Simple Machines Community Forum. Please login or sign up.
September 28, 2021, 12:48:32 PM

News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord


<Next Page> tag on messages with multiple pages

Started by c5Quad, December 09, 2007, 08:22:49 PM

Previous topic - Next topic

c5Quad

I would like to see a <Next Page> (or something similar) on messages with multiple pages so you don't have to click on the next number to go to the next page.

Oldiesmann

How would clicking "Next Page" be any different than clicking the next number in the list?
Michael Eshom
Cincy Space - now open!

karlbenson

It might also get a little confusing since there is already a next and previous link on the page to take the user to the prev next topic.

c5Quad

January 07, 2008, 09:59:33 PM #3 Last Edit: January 07, 2008, 10:15:53 PM by c5Quad
I was thinking more of like this:
________________________________
|1 of 5 | 1 | 2 | 3 | <NEXT><LAST> |
------------------------------------


Some people do not have the dexterity to click the small numbers.  And with voice dictation i.e. Dragon NaturallySpeaking, they could just say next instead of the numbers, which is sometimes hard for voice dictation to understand.  In my example I don't think people would be  about the links between the next page and the next article.  Just a thought, not a major issue.

nwobhm

Quote from: c5Quad on January 07, 2008, 09:59:33 PM
I was thinking more of like this:
________________________________
|1 of 5 | 1 | 2 | 3 | <NEXT><LAST> |
------------------------------------


Some people do not have the dexterity to click the small numbers.  And with voice dictation i.e. Dragon NaturallySpeaking, they could just say next instead of the numbers, which is sometimes hard for voice dictation to understand.  In my example I don't think people would be  about the links between the next page and the next article.  Just a thought, not a major issue.
This is kind old topic, but this is just what I was looking for.
This next-previous -page buttons would make browsing with cellphone bit easier.

Or can I convert those next - previous topic buttons to point to a page not topic?

Antechinus

March 16, 2010, 09:24:35 PM #5 Last Edit: March 16, 2010, 09:32:10 PM by Antechinus
I've been looking for this functionality for a mobile theme I'm working on. I've sorted the coding for 1.1.11 and 2.0 RC3. This works on all templates.

I adapted the coding from this post and changed it to suit my preferences.

Changes are:

1/ I omitted the code for "First page" and "Last page" links as I thought they were redundant and added too much clutter. First page can be accessed from the linktree anyway. Last page can be accessed from the last number in the pages string, or several other ways depending on which page you are on (reverse sorting options, last post icons, reply button, etc).

2/ "Previous page" link only displays if there is more than one page and you are not on the first page.

3/ "Next page" link only displays if there is more than one page and you are not on the last page.

For Subs.php in 1.1.11 the code is:

{
// If they didn't enter an odd value, pretend they did.
$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;

$pageindex = '';

// Show 'Prev'
if ($start >= $num_per_page)
$pageindex .= sprintf($base_link, $start - $num_per_page, ' <b>&#171; Previous page</b>');

// Show the first page. (>1< ... 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * $PageContiguous)
$pageindex .= sprintf($base_link, 0, '1');
else
$pageindex .= '';

// Show the ... after the first page.  (1 >...< 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * ($PageContiguous + 1))
$pageindex .= '<b> ... </b>';

// Show the pages before the current one. (1 ... >6 7< [8] 9 10 ... 15)
for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
if ($start >= $num_per_page * $nCont)
{
$tmpStart = $start - $num_per_page * $nCont;
$pageindex.= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the current page. (1 ... 6 7 >[8]< 9 10 ... 15)
if (!$start_invalid)
$pageindex .= '[<b>' . ($start / $num_per_page + 1) . '</b>] ';
else
$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);

// Show the pages after the current one... (1 ... 6 7 [8] >9 10< ... 15)
$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
if ($start + $num_per_page * $nCont <= $tmpMaxPages)
{
$tmpStart = $start + $num_per_page * $nCont;
$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the '...' part near the end. (1 ... 6 7 [8] 9 10 >...< 15)
if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
$pageindex .= '<b> ... </b>';

// Show the last number in the list. (1 ... 6 7 [8] 9 10 ... >15<)
if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);

// Show 'Next'.
$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
if (($display_page <= $tmpMaxPages)&&($tmpMaxPages > 1))
$pageindex .= sprintf($base_link, $display_page, '<b>Next Page &#187;</b>');

}


For 2.0 RC3 in Subs.php the code is:

{
// If they didn't enter an odd value, pretend they did.
$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;

$pageindex = '';

// Show 'Prev'
if ($start >= $num_per_page)
$pageindex .= sprintf($base_link, $start - $num_per_page, ' <b>&#171; Previous page</b>');

// Show the first page. (>1< ... 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * $PageContiguous)
$pageindex .= sprintf($base_link, 0, '1');
else
$pageindex .= '';

// Show the ... after the first page.  (1 >...< 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * ($PageContiguous + 1))
$pageindex .= '<span style="font-weight: bold;" onclick="' . htmlspecialchars('expandPages(this, ' . JavaScriptEscape($base_url . ';start=%1$d') . ', ' . $num_per_page . ', ' . ($start - $num_per_page * $PageContiguous) . ', ' . $num_per_page . ');') . '" onmouseover="this.style.cursor = \'pointer\';"> ... </span>';

// Show the pages before the current one. (1 ... >6 7< [8] 9 10 ... 15)
for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
if ($start >= $num_per_page * $nCont)
{
$tmpStart = $start - $num_per_page * $nCont;
$pageindex.= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the current page. (1 ... 6 7 >[8]< 9 10 ... 15)
if (!$start_invalid)
$pageindex .= '[<strong>' . ($start / $num_per_page + 1) . '</strong>] ';
else
$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);

// Show the pages after the current one... (1 ... 6 7 [8] >9 10< ... 15)
$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
if ($start + $num_per_page * $nCont <= $tmpMaxPages)
{
$tmpStart = $start + $num_per_page * $nCont;
$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the '...' part near the end. (1 ... 6 7 [8] 9 10 >...< 15)
if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
$pageindex .= '<span style="font-weight: bold;" onclick="expandPages(this, \'' . ($flexible_start ? strtr($base_url, array('\'' => '\\\'')) : strtr($base_url, array('%' => '%%', '\'' => '\\\'')) . ';start=%1$d') . '\', ' . ($start + $num_per_page * ($PageContiguous + 1)) . ', ' . $tmpMaxPages . ', ' . $num_per_page . ');" onmouseover="this.style.cursor=\'pointer\';"> ... </span>';

// Show the last number in the list. (1 ... 6 7 [8] 9 10 ... >15<)
if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);

// Show 'Next'.
$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
if (($display_page <= $tmpMaxPages)&&($tmpMaxPages > 1))
$pageindex .= sprintf($base_link, $display_page, '<b>Next Page &#187;</b>');

}


Note that there is one very small bug in RC3. If you are on the message index or on the unread posts/replies indexes then any threads which have more than one page will show like this:

Welcome to SMF!
Started by Simple Machines « 1 2 3 4 5 6 7 8 9 10 11 Next Page » »

This doesn't bother me since I'll just remove the pages string for the threads on those templates. I can't really see any need for it to be there since people will either want the start of the thread (click thread title) or the first new post (click "New" icon) or the last post (click last post icon hey :P). I also can't see it's worth writing another separate function to deal with it. Having the number of pages in each thread listed on those templates is just redundant markup IMO and adds nothing worth having.


ETA: I think I might package this one up as a mod.

Arantor

That looks like fun, only thing you'll have to change is turn the 'Previous page' and so on into proper language strings but that's not exactly a challenge.

I like it :)
No good deed goes unpunished
All helpful urges should be circumvented

Antechinus

No, I can't see that being a major challenge. ;D

Oh yeah, the original code in that other thread was set so that the next and previous links only showed if you weren't on the first and last pages OR on the second or second last pages. In other words, on a two or three or four page thread they didn't show at all, which kinda defeats the purpose IMO.

Antechinus

Funny thing happened when I tried changing the hard coded text to a proper language string. For some reason the text wont display unless it is hard coded. I tried the strings in index.english.php and in Modifications.english.php but they don't work in either. Yet as soon as the text is hard coded they work.

ETA: And yes I did define $txt as a global in the page index function so it isn't that. Not sure what is going on.

Arantor

1.1 or 2.0? If you did it in 2.0, clear the file cache first.

If that doesn't work, I'll be happy to look at the code and see if I can figure it out for you.
No good deed goes unpunished
All helpful urges should be circumvented

Antechinus

1.1.x. I tried clearing cache anyway in case it was a browser hangup. Standard procedure for code changes. ;)

I'll play with it a bit more since it was late and I may have missed something obvious.

Antechinus

Ok, here's another spanner to throw into the works. One of the other admins said this:

QuoteI hate the way navigation works in threads. Browsers recognize so-called navigation links, which are located in the header tag, e.g.:
<link rel="next" href="http://www.councilofexmuslims.com/index.php?topic=4620.0;prev_next=next" />

When you tell the browser to "go to the next page", it will —thanks to this stupid link tag— go to the next thread and not to the next page of the current thread. Hell, that's annoying! I would like the link tags (rel="next" and rel="prev") to point to the next and previous page respectively, but when there are no pages left, the links should point to the next or previous thread.

Which makes a lot of sense for people who use that functionality of their browsers rather than manually scrolling the cursor to the link before clicking it. So, how would one re-code the relative links so they hook up to the next page in a topic rather than to the next topic?

If they don't automatically go to the next topic when the current one runs out of pages that would still be fine, but they should at least be able to cycle through pages in the current topic.

Arantor

You know what? This one surprised me how easy it was to fix, it isn't funny. It's already actually figured out by Display.php

index.template.php (I'm using 1.1 default here but the principle is the same for 2.0)

Code (find) Select
// If we're viewing a topic, these should be the previous and next topics, respectively.
if (!empty($context['current_topic']))
echo '
<link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />
<link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';


Code (replace) Select
// If we're viewing a topic, these should be the previous and next topics, respectively.
if (!empty($context['current_topic']) && !empty($context['links']['prev']))
echo '
<link rel="prev" href="', $context['links']['prev'], '" />
<link rel="next" href="', $context['links']['next'], '" />';
No good deed goes unpunished
All helpful urges should be circumvented

Antechinus

What? ;D Coooooooooooool. I love it when it's an easy fix. This whole thing needs to be another mod methinks, as soon as I figure out what is up with the language string.

Anyway this is what works, with hard-coded text:

{
// If they didn't enter an odd value, pretend they did.
$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;

$pageindex = '';

// Show 'Prev'
if ($start >= $num_per_page)
$pageindex .= sprintf($base_link, $start - $num_per_page, '<span class="nextprev">&#171; Previous page</span>');

// Show the first page. (>1< ... 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * $PageContiguous)
$pageindex .= sprintf($base_link, 0, '1');
else
$pageindex .= '';

// Show the ... after the first page.  (1 >...< 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * ($PageContiguous + 1))
$pageindex .= '<b> ... </b>';

// Show the pages before the current one. (1 ... >6 7< [8] 9 10 ... 15)
for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
if ($start >= $num_per_page * $nCont)
{
$tmpStart = $start - $num_per_page * $nCont;
$pageindex.= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the current page. (1 ... 6 7 >[8]< 9 10 ... 15)
if (!$start_invalid)
$pageindex .= '[<b>' . ($start / $num_per_page + 1) . '</b>] ';
else
$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);

// Show the pages after the current one... (1 ... 6 7 [8] >9 10< ... 15)
$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
if ($start + $num_per_page * $nCont <= $tmpMaxPages)
{
$tmpStart = $start + $num_per_page * $nCont;
$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the '...' part near the end. (1 ... 6 7 [8] 9 10 >...< 15)
if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
$pageindex .= '<b> ... </b>';

// Show the last number in the list. (1 ... 6 7 [8] 9 10 ... >15<)
if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);

// Show 'Next'.
$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
if (($display_page <= $tmpMaxPages)&&($tmpMaxPages > 1))
$pageindex .= sprintf($base_link, $display_page, '<span class="nextprev">Next page &#187;</span>');

}


If I change it to this, with $txt included in globals at the start of the function and the strings defined in index.english.php then for some reason the text wont display:

{
// If they didn't enter an odd value, pretend they did.
$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;

$pageindex = '';

// Show 'Prev'
if ($start >= $num_per_page)
$pageindex .= sprintf($base_link, $start - $num_per_page, '<span class="nextprev">',$txt['pi_prev'],'</span>');

// Show the first page. (>1< ... 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * $PageContiguous)
$pageindex .= sprintf($base_link, 0, '1');
else
$pageindex .= '';

// Show the ... after the first page.  (1 >...< 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * ($PageContiguous + 1))
$pageindex .= '<b> ... </b>';

// Show the pages before the current one. (1 ... >6 7< [8] 9 10 ... 15)
for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
if ($start >= $num_per_page * $nCont)
{
$tmpStart = $start - $num_per_page * $nCont;
$pageindex.= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the current page. (1 ... 6 7 >[8]< 9 10 ... 15)
if (!$start_invalid)
$pageindex .= '[<b>' . ($start / $num_per_page + 1) . '</b>] ';
else
$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);

// Show the pages after the current one... (1 ... 6 7 [8] >9 10< ... 15)
$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
if ($start + $num_per_page * $nCont <= $tmpMaxPages)
{
$tmpStart = $start + $num_per_page * $nCont;
$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the '...' part near the end. (1 ... 6 7 [8] 9 10 >...< 15)
if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
$pageindex .= '<b> ... </b>';

// Show the last number in the list. (1 ... 6 7 [8] 9 10 ... >15<)
if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);

// Show 'Next'.
$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
if (($display_page <= $tmpMaxPages)&&($tmpMaxPages > 1))
$pageindex .= sprintf($base_link, $display_page, '<span class="nextprev">',$txt['pi_next'],'</span>');

}


With index.english.php being this:

$txt['pi_next'] = 'Next page &#187;';
$txt['pi_prev'] = '&#171; Previous page';

Arantor

And you're using English not English-UTF8 and emptied the file cache appropriately? Hmm.
No good deed goes unpunished
All helpful urges should be circumvented

Antechinus

Using English ISO and it's 1.1.x so there is no file cache. I cleared the browser cache anyway though.

Arantor

And is it just missing, or is it throwing an error too?
No good deed goes unpunished
All helpful urges should be circumvented

Antechinus

Just missing. No errors in the admin log.

ETA: The empty <span class="nextprev"> is echoing to the browser but of course is not visible without any content.

Arantor

Does it make a difference if you use $txt['previous_next_back'] and $txt['previous_next_forward'] instead of the ones you had?
No good deed goes unpunished
All helpful urges should be circumvented


Advertisement: