Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-09-06 03:36:55

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

wraptag for txp:older/newer/link_to...

I may be missing something, but I find it odd that <txp:newer></txp:newer>, <txp:older></txp:older>, and <txp:link_to...></txp:link_to...> don’t have a wraptag attribute.

What I want to achieve is something like this:

<ul id="pager">
<txp:older wraptag="li"><txp:text item="older" /></txp:older>
<txp:newer wraptag="li"><txp:text item="newer" /></txp:newer>
</ul>

Instead of this:

<ul id="pager">
<li class="prev"><txp:older showalways="1"><txp:text item="older" /></txp:older></li>
<li class="next"><txp:newer showalways="1"><txp:text item="newer" /></txp:newer></li>
</ul>

The first snippet won’t render an empty <li> if there is no output.

Last edited by maniqui (2007-09-06 03:37:07)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#2 2007-09-06 09:10:03

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: wraptag for txp:older/newer/link_to...

There’s a second problem you’ll run into. When there is neither a previous or a next page (and you manage to avoid the empty (<li></li>), you get an empty <ul></ul> construct which is invalid.

Offline

#3 2007-09-06 12:26:21

guiguibonbon
Member
Registered: 2006-02-20
Posts: 296

Re: wraptag for txp:older/newer/link_to...

<txp:php>
	global $pretext;
	$out = "";
	if ($pretext['prev_id']) 
		$out .= '<li class="prev"><txp:link_to_prev><txp:prev_title /></txp:link_to_prev></li>';
	if ($pretext['next_id']) 
		$out .= '<li class="next"><txp:link_to_next><txp:next_title /></txp:link_to_next></li>';
	if ($out != "")
		echo parse('<ul id="neighbours">'.$out.'</ul>');
</txp:php>

mmmh…

yuk.

Edited to match with link_to_… (see below)

Last edited by guiguibonbon (2007-09-06 13:31:39)

Offline

#4 2007-09-06 12:33:20

guiguibonbon
Member
Registered: 2006-02-20
Posts: 296

Re: wraptag for txp:older/newer/link_to...

oh, no, sorry that would have been for link_to_prev and link_to_next.

second try :

<txp:php>
	global $thispage;
	$numPages = $thispage['numPages'];
	$pg = $thispage['pg'];
	$out = "";
	if ($numPages > 1 and $pg > 0 and $pg < $numPages) 
		$out .= '<li class="prev"><txp:older showalways="1"><txp:text item="older" /></txp:older></li>';
	if ($numPages > 1 and $pg > 1 and $pg <= $numPages)
		$out .= '<li class="next"><txp:newer showalways="1"><txp:text item="newer" /></txp:newer></li>';
	if ($out != "")
		echo parse('<ul id="pager">'.$out.'</ul>');
</txp:php>

Last edited by guiguibonbon (2007-09-06 12:35:47)

Offline

#5 2007-09-06 12:49:09

guiguibonbon
Member
Registered: 2006-02-20
Posts: 296

Re: wraptag for txp:older/newer/link_to...

perfect world scenario :

<txp:if_page>
<ul id="pager">
<txp:older wraptag="li" class="older"><txp:text item="older" /></txp:older>
<txp:newer wraptag="li" class="newer"><txp:text item="newer" /></txp:newer>
</ul>
</txp:if_page>

add to taghandlers.php :

function if_page($atts, $thing) {
global $thispage;
return parse(EvalElse($thing, ($thispage['numPages'] > 1)));
}

Offline

#6 2007-09-06 13:18:00

guiguibonbon
Member
Registered: 2006-02-20
Posts: 296

Re: wraptag for txp:older/newer/link_to...

and while we’re at it :

function if_page($atts, $thing){

global $thispage;

extract(lAtts(array( 'page' => '' ), $atts));

if ($page)
	return parse(EvalElse($thing, in_list($thispage['pg'], $page)));

else
	return parse(EvalElse($thing, ($thispage['numPages'] > 1)));

}

Last edited by guiguibonbon (2007-09-06 13:19:04)

Offline

#7 2007-09-06 13:26:24

guiguibonbon
Member
Registered: 2006-02-20
Posts: 296

Re: wraptag for txp:older/newer/link_to...

ah, hell, and why not :

function if_neighbours($atts, $thing) {

global $pretext, $is_article_list;

extract($pretext);

$cond = ($is_article_list != true && ($prev_id || $next_id));

return parse(EvalElse($thing, $cond));

}

Offline

#8 2007-09-06 14:09:47

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: wraptag for txp:older/newer/link_to...

Hi guiguibonbon.

Thanks for creating and sharing this functionality. I haven’t tested it yet. (Also, I’m not a fan of hacking TxP files but that’s another story…)

Just to know: what will if_neightbours do? It’s like if_page but for individual articles?

Thanks again.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#9 2007-09-06 14:31:37

guiguibonbon
Member
Registered: 2006-02-20
Posts: 296

Re: wraptag for txp:older/newer/link_to...

Just to know: what will if_neightbours do? It’s like if_page but for individual articles?

Yup. If someone wants to make a plugin out of them, please do. If devs want to add it to the core, that would be nice too. I think these might be useful in other scenarios too.

You’d still need the wraptag attribute though.

Last edited by guiguibonbon (2007-09-06 14:54:08)

Offline

#10 2007-09-06 14:48:33

guiguibonbon
Member
Registered: 2006-02-20
Posts: 296

Re: wraptag for txp:older/newer/link_to...

unless…

function if_page($atts, $thing) {

	global $thispage;

	extract(lAtts(array( 'page' => '' ), $atts));

	extract($thispage);

	if ($page) {
		$page = ($page == "last") ? $numPages : $page;
		return parse(EvalElse($thing, in_list($pg, $page)));
	}

	return parse(EvalElse($thing, ($numPages > 1)));

}

use :

<txp:if_page>
	<ul id="pager">
</txp:if_page>

<txp:if_page page="1"><txp:else/>
	<li class="prev"><txp:older><txp:text item="older" /></txp:older></li>
</txp:if_page>

<txp:if_page page="last"><txp:else/>
	<li class="next"><txp:newer><txp:text item="newer" /></txp:newer></li>
</txp:if_page>

<txp:if_page>
	</ul>
</txp:if_page>

ok, that’s ugly. Would have been slightly less ugly if we had the new parser, but hey…

and yes, this should all be tested.

Edit: sorry, this was full of errors, fixed now.

Edit 2: removed showalways since the tags won’t even be parsed if there’s no previous or next page. If you’d like the li without the link to be displayed anyway :

<txp:if_page>
	<ul id="pager">
</txp:if_page>

<txp:if_page page="1">
	<li class="prev"><txp:text item="older" /></li>
<txp:else/>
	<li class="prev"><txp:older><txp:text item="older" /></txp:older></li>
</txp:if_page>

<txp:if_page page="last">
	<li class="next"><txp:text item="newer" /></li>
<txp:else/>
	<li class="next"><txp:newer><txp:text item="newer" /></txp:newer></li>
</txp:if_page>

<txp:if_page>
	</ul>
</txp:if_page>

Last edited by guiguibonbon (2007-09-06 15:07:44)

Offline

#11 2007-09-06 15:44:43

guiguibonbon
Member
Registered: 2006-02-20
Posts: 296

Re: wraptag for txp:older/newer/link_to...

BTW, devs, don’t know if this has been brought up before, but I’m always confused by these tags’ names. I think they should be renamed txp:link_to_prev_page and txp:link_to_next_page. Older and newer don’t mean a thing, since you can sort your articles in reverse order. It would also harmonize things with txp:link_to_prev and txp:link_to_next. Maybe create an alias function, for backwards compatibility?

And is it just me, or do these tags actually do the reverse of what their names suggest?

Or is it the documentation that has it wrong ?

<txp:older>Previous</txp:older>
<txp:newer>Next</txp:newer>

Shouldn’t that be the reverse, or :

<txp:newer>previous page</txp:newer> // link to p-1
<txp:older>next page</txp:older> // link to p+1

I’m telling you : confusing.

Last edited by guiguibonbon (2007-09-06 19:01:09)

Offline

#12 2007-09-06 15:52:04

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Re: wraptag for txp:older/newer/link_to...

the problem with changing tag names is that of backward compatibility. By now there are thousands of sites which use txp, probably most of which, are maintained by clients and not designers. Change of tags would mean a lot of work, in some cases, for those here who maintain their clients’ sites.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB