Why is the page_index shown when there is only one page?

Started by Kolya, February 13, 2010, 05:36:06 PM

Previous topic - Next topic

Kolya


hadesflames


Arantor

You mean just Pages: [1] ?

Because it's confirming there is only one page.

Kolya

Yes that's the one. Reporting the lack of additional pages is nonsense.

Is there a way to prevent this behaviour?

Arantor

Not without modifying Subs.php

But actually, how often do you see "Page 1 of 1"?

Kolya

Not often, and if I do it's usually some machine printed sheet from a government agency. Not a standard I'd hold SMF up to. :)

I'm fine with editing Subs.php but would need a bit of help with checking for 1 page.

Arantor

* Arantor looks back at Subs.php, and constructPageIndex... which doesn't include the language string.

Actually, it's a little more involved. You'll have to edit every single place it's actually used, basically every place in SMF that you find $txt['pages']...

Kolya


Arantor

OK, simplest route to doing it.

After:
function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false)
{
global $modSettings;


Add:
if ($max_value > $num_per_page)
return '';


Then, wherever $txt['pages'] is called for, construct a ternary expression kind of like so:

(!empty($context['page_index']) ? $txt['pages'] . ': ' . $context['page_index'] : '')

I'm not sure it's $context['page_index'] on every page though... but that's the process.

Kolya

Quote from: Arantor on February 13, 2010, 06:38:44 PM

if ($max_value > $num_per_page)
return '';

That keeps the page counter from showing up even if there's more than one page. :/

Arantor

Argh, brainfried.

if ($max_value <= $num_per_page)
return '';

Kolya


Kolya

It turns out this hack has an unwanted side-effect: After posting, when you're being redirected to the thread you just posted in, you land on a page that contains solely the post you just made. The same will happen when clicking on any "NEW" links. This makes it rather unusable.

Looks like I found the reason why the page_index is shown when there is only one page: The reason is that SMF uses the same function to create pages as well as display the page index.

Arantor

constructPageIndex is used in SO many places it isn't funny :(

Kolya

I guess I could check on the page if $page_index == 1 and then don't display anything

If that won't work I'll copy the whole function, insert your hack, then make it return a new variable, say $page_index_display

I'll try those solutions later today and report back.


Kolya

Yeah well I didn't get very far with those ideas.

The first solution which would have been the more viable one I guess looked like this:

(($context['page_index'])==1) ? '': $context['page_index']


I also tried string comparison for the brackets:

(($context['page_index'])=="[1]") ? '': $context['page_index']


None of that worked, and I'm still in need of a decent solution for this.

Arantor

Well, the return value is actually going to be "[<strong>1</strong>]" that you'll be looking for.

Kolya

That was a good hint. In the end it turned out to be "[<strong>1</strong>] " (Note the space.)
Anyway, this works now. Thanks again for your help, Arantor. It's appreciated.

Advertisement: