Re: Customising function constructPageIndex (nasty evil stuffz)

dimanche 6 juillet 2014

Ok all you back end geniuses, I am needing a bit of guidance here. :D

What I want to do is a better implementation of "Previous page" and "Next page" buttons for function constructPageIndex, as well as adding some decent styling hooks to the same, and turning the whole shebang into a proper list (which it really ought to be).


The way I want to do this is by assigning an extra class to the existing class="navPages" where I want it. This is better than just chucking in extra spans all over the place (ye olde 2.1 method) for two reasons. First it's cleaner markup. Second, it will make for cleaner and more versatile CSS, because you will be able to style all elements with one basic class, and change specific anchors rather than having to play with spans inside them. You know you want it (you can even steal it for 2.1 ;)).


At the moment the 2.0.x base link is generated as this:


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

I can sort out turning it into a list, simply by changing the base link generation to this:


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

With template calling it as this:


<div class="pagesection">

<ul class="pagelinks"><li class="stupid_bloat_for_teh_extra_uglies">', $txt['pages'], '</li>', $context['page_index'], '</li>

</div>


Which will enable me to easily hide the redundant text that tells me something I already knew: that these are "Pages:". :P

The tricky bit (for me) is assigning an extra class to the base link anchor. This would have to be handled in a couple of places, and is going to require some conditionals. The basic way of doing it is to use this for the "Previous page" button:


// Show 'Prev'

if ($start >= $num_per_page)

$pageindex .= sprintf($base_link, $start - $num_per_page, ' <span class="previous_page">'. $txt['previous page']. '</span>');

I want to change that to this:


[code]// Show 'Prev'

if ($start >= $num_per_page)

$pageindex .= sprintf($base_link, $start - $num_per_page, $txt['previous page']);

And have the base link sorted out so that it will generate this:


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

Obviously the base link also has to generate this for the "Next page" link:


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

Short version: I need an extra variable in the base link markup, like this:


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

And some way of getting the right class assigned to %stuffz.

Any takers? :D






0 commentaires:

Enregistrer un commentaire

 

Lorem

Ipsum

Dolor