News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Is it possible to add #SOMETHING to links generated by constructPageIndex?

Started by Biology Forums, August 31, 2016, 01:46:49 AM

Previous topic - Next topic

Biology Forums

Is it possible to add #ID to links generated by constructPageIndex?

If so, how?


Matthew K.

Since your question is "can you", the answer is yes. To be more helpful, you'll need to explain to us what you're trying to do.

Biology Forums

Cool!

I have the following code:

$maxComments = 10; // Hard-coded; should this be configurable?

// Make sure the starting place makes sense and construct our friend the page index.
$context['start'] = (int)$_REQUEST['start'];
$context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID, $context['start'], $commentCount, $maxComments, false);


I'd like: http://myurl.com/index.php?action=profile;u=6;start=20#comments

How would I incorporate the fragment (#)?

Matthew K.

On the train currently, so I'm not able to write the code for you, but I'll mark this unread and when I get back to my place I'll write the code if no one else has.



Pipke

You want it to use it on one page (ie. once on the script you posted) or on all the pages wich uses the smf 'pagination' function constructPageIndex?
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕


Pipke

ok if i understand you right here goes:

in Sources/Subs.php

Code (find) Select

$base_link = '<a class="navPages" href="' . ($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d') . '">%2$s</a> ';


Code (replace with) Select

$base_link = '<a class="navPages" href="' . ($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d') . '#comments">%2$s</a> ';


url will be then: 
http://myurl.com/index.php?action=profile;u=6;start=20#comments
or
http://myurl.com/index.php?topic=1.10#comments
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Matthew K.

Pipke, that's almost correct. You also need some conditional on whether #comments should be set or not.

Biology Forums

I think I misunderstood you. This will put #comment on every constructPageIndex in the forum.

Pipke

Quote from: Stylus on September 07, 2016, 03:10:48 PM
Thanks -- on all pages
Quote from: Stylus on September 08, 2016, 12:14:03 AM
I think I misunderstood you. This will put #comment on every constructPageIndex in the forum.

yes, you said on all?
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Biology Forums

Let me be clear, on all for where the function is embedded.

I.e. if it is embedded in page.template.php, it shows #comment on every page for the page index on page.template.php. Otherwise, I could have figured it out :-\

Thanks

Pipke

try this then:

in Sources/Subs.php

Code (find) Select

function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false)


Code (replace with) Select

function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false, $comments = null)


and do...

Code (find) Select

$base_link = '<a class="navPages" href="' . ($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d') . '">%2$s</a> ';


Code (replace with) Select

$base_link = '<a class="navPages" href="' . ($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d') . ($comments ? '#comments' : '') .'">%2$s</a> ';


now use your code as this:

$maxComments = 10; // Hard-coded; should this be configurable?

// Make sure the starting place makes sense and construct our friend the page index.
$context['start'] = (int)$_REQUEST['start'];
$context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID, $context['start'], $commentCount, $maxComments, false, $comments = true);


Let me know if that worked out for you?

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Biology Forums

Great idea. What I did was:

function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false, $fragment = null)

and

$base_link = '<a class="navPages" href="' . ($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d') . ($fragment ? $fragment : '') .'">%2$s</a> ';

Thanks for the idea

Advertisement: