Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-07-23 21:15:45

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Pagination Problem

I need help….

My example URL
http://site.dev/?s=rent&where=&type=&price=&bed=&bath=&pg=1

I have used every pagination plugin out there
“ob1_pagination”, <txp:next />, “<txp:soo_page_numbers />”

I am going bit put of control… I am trying create a pagination with “next” button

When I click it, my result: http://site.dev/rent/?pg=2

Is there anyway I could use php or jquery to pick up and replace the last letter with +1 so I can stay on the current URL


<txp:way_too_cool />

Offline

#2 2011-07-23 22:37:28

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Pagination Problem

Is there anyway I could hack ob1_pagination plugin to add extra variables


<txp:way_too_cool />

Offline

#3 2011-07-23 22:49:32

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Pagination Problem

You could probably loop thought the GET variables that are set, and pick those you want to append to the URI.

For example, a script similar to this could probably do it. The script builds an URL from the GET variables other than pg and s, as those will be in the native pagination link.

<txp:variable name="append_uri"><txp:php>

	/*
		Get the array of GET values if any
	*/

	$get = isset($_GET) && is_array($_GET) ? $_GET : array();

	/*
		Go trough the values one by one
	*/

	$out = array();

	foreach($get as $name => $value) {

		/*
			Exclude the values that aren't needed.
			In this case include everything else than 's' and 'pg'.
			'pg' is already in the link and so is the section.
		*/

		if(!in_array($name, array('s','pg')))
			$out[] = htmlspecialchars($name.'='.gps($name));
	}

	echo $out ? '&amp;' . implode('&amp;', $out) : '';

</txp:php></txp:variable>

I’ve wrapped the PHP in a TXP’s variable named append_uri so that it’s easier to re-use in multiple occasions (in both newer and older link). Then to use, you can just append it to the page URL, like so:

<txp:newer>
	<a href="<txp:newer /><txp:variable name="append_uri" />">
		Some more stuff
	</a>
</txp:newer>

I haven’t tested any of it, so it might not work, but probably should — or dies an horrific death.

Offline

#4 2011-07-23 22:55:40

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Pagination Problem

Result

http://site.dev/category/rent/&c=rent&where=&type=&price=&bed=&bath=


<txp:way_too_cool />

Offline

#5 2011-07-23 23:03:13

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Pagination Problem

Dimitri wrote:

Result

http://site.dev/category/rent/&c=rent&where=&type=&price=&bed=&bath=

As it should, right? All the URL parameters are right there. The variable only contains all the additional URL parameters you wanted. Obviously you will also make sure that there is a next or previous page available. Thus the newer container tag.

See:

Offline

#6 2011-07-23 23:04:39

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Pagination Problem

What I want is from

http://site.dev/?s=rent&where=&type=&price=&bed=&bath=&pg=1
to
http://site.dev/?s=rent&where=&type=&price=&bed=&bath=&pg=2


<txp:way_too_cool />

Offline

#7 2011-07-23 23:07:09

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Pagination Problem

Dimitri wrote:

What I want is from

The code does exactly that. The newer and older links will output all the additional stuff when used in correct context.

Also, you don’t need the section, as it’s already included in the URL in clean format. You can use <txp:section /> output section in your page templates.

Offline

#8 2011-07-23 23:14:28

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Pagination Problem

Sorry I am doing something rather complicated with the advanced search. Hard to explain. Maybe you could help me with this one, not getting anywhere

//----- Trying to make this work
<txp:variable name="pagey" value="<txp:page_url type='pg' />" />
<txp:adi_calc name="pagey" add="1" display="1" />
---------//

<a href="?c=<txp:category />&amp;where=<txp:variable name='where' />&amp;type=<txp:variable name='type' />&amp;price=<txp:variable name='price' />&amp;bed=<txp:variable name='bed' />&amp;bath=<txp:variable name='bath' />&amp;pg=<txp:variable name='pagey' />" >Next</a>

<txp:way_too_cool />

Offline

#9 2011-07-23 23:35:38

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Pagination Problem

Got what I wanted. The reason for this, I built my own advanced search, so the pagination keeps breaking my templetes structure

Link

<txp:variable name="page"><txp:page_url type="pg" /></txp:variable>
//Look at the end of the opening <a> tag
<txp:article>
    <txp:if_last_article>
          <a href="?c=<txp:category />&amp;where=<txp:variable name='where' />&amp;type=<txp:variable name='type' />&amp;price=<txp:variable name='price' />&amp;bed=<txp:variable name='bed' />&amp;bath=<txp:variable name='bath' />&amp;pg=<txp:adi_calc name='page' add='1' display='1' />" >Next</a>
     </txp:if_last_article>
</txp:article>

<txp:way_too_cool />

Offline

Board footer

Powered by FluxBB