Jump to content
Peter Troeger

[SOLVED - kind of] Pagintion Link redirects

Recommended Posts

Hello 🙂

I have set up pagination on a mulitlanguage site.
I've done this before, but this time I have a problem I can't solve.
Pagination is activated on 'parent-template' and 'child-template' just to be sure 🙂

This is my code:

$children = $page->children('limit=1');
		
foreach($children as $child) {
	$title = $child->title;
	echo $title;
}
		
echo $children->renderPager();

The navigation is output correctly and the link look correct as well 'parent-page/page2/'.
But when I click the link, the site seems to redirect back to 'parent-page/

Any help would be greatly appreciated 🙂

- Peter

Share this post


Link to post
Share on other sites

Just a few thoughts...

  • Are there enough children/pages?
  • The selector needs limit AND start if I remember correctly.
  • Home (id=1) needs correct url settings for each language (for example: blank, de, fr, ...)
  • Enable config->debug to see if there are warnings and take a look at the logs - just to make sure.

Just looked into Pagination in ProcessWire but didn't find anything special you could try in addition to that.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for your reply!

  • I have 32 child pages, and it generates the navigation correctly with multiple pages.
  • I added a start, but that didn't change it.
  • URL settings are set to blank for the default and pt for the second language. I tried changing the default to de, just in case but the problem still exists.
  • debug is already enabled. No errors are logged.

I only have menubuilder and the login/register plugin for sitewide modules installed. Could it have anything to do with PagePathHistory?

Share this post


Link to post
Share on other sites

Ok... those modules you mentioned shouldn't interfere here in any kind. Even PagePathHistory shouldn't kick in there but you can check if there is anything set in the settings tab.

Could you post the whole page could or more than just that snippet? Maybe there is something in it.

Share this post


Link to post
Share on other sites

I found out that, if I remove uikit from my site, the page is not redirected, but stays on ' .parent-page/page2/ '.
It doesn't show the content from page 2 though. It still shows page 1 content.

This is the complete template page.

<?php namespace ProcessWire; 

?>

<div id="body_text">

	<?php
	
		$children = $page->children('start=0, limit=2');
		
		foreach($children as $child) {
			$title = $child->title;
			$body = $child->body;
			$file = $child->file;
			$file_url = $file['url'];
			$image = $child->single_images;
			if ($file=='') $file='#'; 
			
			
			?>
			
			<section class="mitteilung">
			
			<?php
			
			echo '<h2><a href="'.$file_url.'">'.$child->title.'</a></h2>
			<p>'.$body.'</p></section>';
			
		}
	?> 
			
			
			<?php echo $children->renderPager(); ?>
</div>

In the init file I add the uikit file.

Share this post


Link to post
Share on other sites

When I keep the uikit file, but remove the usage of uikit (I've had two instances af ukBlogPosts(pages()->get('/aktuelles/')->children, 1) included in the page),
the redirect doesn't happen anymore either. The content still doesn't change 🙂

Share this post


Link to post
Share on other sites

ok, I also removed the start=0, and now it works. Now I only have to find out, why it doesn't work when I use ukBlogPosts(pages()->get('/aktuelles/')->children, 1 ) and $children->renderPager(); on the same page 🙂

Share this post


Link to post
Share on other sites

Ok... so start is not necessary. Good to know. My fault. 😄 

Where does this ukBlogPosts() come from? Are you using one of the included profiles (Regular or how it is called)?
If so... I'm out... never used it. 😂 

If you don't need it there, you can just go on from here.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Sten
      Sorry I can't find any submit button to save my configuration on a template in the admin interface. The file is fine.
    • By nabo
      Hello
      this is my snippet
      public function init() { if($this->wire('user')->isSuperuser()) { $this->wire()->addHookAfter('ProcessPageEdit::buildFormSettings', $this, 'buildForm'); $this->wire()->addHookBefore('ProcessPageEdit::processInput', $this, 'saveForm'); } } public function buildForm(HookEvent $event) { $p = $event->object->getPage(); $inputfields = $event->return; $fieldset = $this->wire('modules')->get("InputfieldFieldset"); $fieldset->attr('id', 'my_fieldset'); $fieldset->label = __("My Renders"); $fieldset->collapsed = Inputfield::collapsedYes; $field = $this->wire('modules')->get("InputfieldTextarea"); $field->attr('name', 'renders'); $field->attr('value', $p->renders); $field->label = $this->_('Renders'); $fieldset->append($field); $inputfields->append($fieldset); } public function saveForm($event) { $page = $this->pages->get($this->input->post->id); $page->set('renders', $this->input->post->renders); } It builds correctly the inputs, I edit the field renders but when I save the page the value of this inputfield remain blank.
      What's wrong?
    • By carlitoselmago
      I'm building a fieldtype/inputfield to visually select a grid like Bootstrap since it's the first time coding such thing, I'm basing my code in FieldtypeColorPicker since the base structure is the same, a graphical UI helper to finally output a string as value.
      The problem is I try to save the value as something like "1,2,3" referencing the index of each column selected but it gets converted as an int value so "1,2,3" becomes "1" if input random text it gets converted as "0".
      Here is the code:
      https://github.com/carlitoselmago/FieldtypeGridSpace
      Here's an screenshot of how it looks

    • By jacmaes
      I have a series of videos, and the following search form (translated into English here) that allows to filter these videos on the frontend:

      I've built a few of these search forms, but only with text fields, selects and radio buttons. Here I'm using an array with checkboxes ("Level" field above), and it's causing me grief when I try to paginate these results. I've done a lot of searching in the forum and spent too many hours to try to get it to work. Here's how I'm building the selector:
      <?php if(count($input->get)): // Level is an array. Code adapted from Ryan's snippet here: // https://processwire.com/talk/topic/3472-enable-pagination-for-search-results/?tab=comments#comment-38042 if($input->get->level) { $level = array(); foreach($input->get->level as $id) $level[] = (int) $id; // sanitize to INTs $level = implode('|', $level); // convert to 123|456|789 string, ready for selector } else { $level = ''; } $data = array( 'training_type' => array('=', (int) $input->get->training_type), 'duration' => array('=', (int) $input->get->duration), 'level' => array('=', $level), 'limit' => array('=', (int) $input->get->limit) ); $selector = ''; // iterate through the $data we made above to create a selector string foreach($data as $field => $a) { list($operator, $value) = $a; if(empty($value)) continue; // send value to the whitelist so that it can be used in pagination $input->whitelist($field, $value); // append to our selector string $selector .= "$field$operator$value, "; } $videos = $page->children("$selector"); When I hit search, I get the expected results. So far so good. The GET parameters are the following with the options selected in the screenshot above:
      videos/?level[]=1476&level[]=1477&training_type=1473&duration=1485&limit=10 $selector echoes the following as the "level" field is an array with a pipe character:
      level=1476|1477, training_type=1473, duration=1485, limit=10 Now, when paginating these results, the following page (page 2) shows these GET parameters:
      videos/page2/?level=1476|1477&training_type=1473&duration=1486&limit=10 And I think that's where the problem lies. The "level" field is "lost" and I'm getting more results than expected on subsequent pages. If I manually add "page2" to the initial results in the URL, just to test, everything works fine:
      videos/page2/?level[]=1476&level[]=1477&training_type=1473&duration=1486&limit=10 But how can I achieve this in code? Do I need to revert to "level[]=1475&level[]=1477" instead of "level=1476|1477" for the pagination to work correctly, and can you PHP gods illuminate me?
      Any help would be really appreciated, really.
    • By bramwolf
      Hi Guys,

      I found that my site is producing this notice on the front end, even when $config->debug = false and also when admin is
      not even logged in. How do I keep the site from displaying this message to front end users? The notice is about a few vars
      being tested, which in this case aren't defined, how would I stop that from happing all together when testing vars? if I for instance
      wrap the $discountCode = blabla in a if($order) { ...  } statement than I'm again testing for $order which isn't a object in this case
      which throws another notice..

      This is the notice:


      Here is my current code:
      // PAD DISCOUNT CODE HOOK // First we see if we have active discount code if ($this->session->orderId) { $order = $this->pages->get($this->session->orderId); } if($product->geen_korting == 1) { $nodisc = $product->geen_korting; } else { $nodisc = $product->parent->geen_korting; } $discountCode = $this->sanitizer->selectorValue($order->pad_discount_code); $dc = $this->pages->get("template=paddiscount, title=$discountCode"); if ($dc->id) { if ($nodisc) { $discount = 0; } elseif ($dc->pad_percentage) { $discount = $newprice * ($dc->pad_percentage / 100); } } $event->return = $newprice - $discount;
      Thanks in advance 🙂
×
×
  • Create New...