bwakad Posted May 26, 2014 Posted May 26, 2014 Ryan suggested it's alway's better to use $input->get... I am not sure how to do this for my link, maybe it need to be changed I think? But I hope someone can give me a solution to my pagination problem. EDIT - based on Horst suggestion --------------- but still some issues $input = wire("input"); My link on the template is this: <a href="<?php echo $page->url;?>?sort=title">Title ASC</a> In my function the code to retrieve the url is this: // get variable sort from url $sort = $input->get->sort; switch ($sort) { case 'title' : $sort="title"; break; case '-title' : $sort="-title"; break; case 'id' : $sort="id"; break; case '-id' : $sort="-id"; break; default : $sort="{$page->name}"; break; } Then I looked for hours in the forum and finally used this from the skyscrapers, thinking sanitizing is good: // Do we have a get variable? if ($input->get->sort) { // Sanitize it $sort = wire('sanitizer')->name(wire('input')->get->sort); // Add it to the whitelist... with the same name as the get var! $input->whitelist('sort', $sort); } I know there was something like: selectorValue, but I was unable to use it in the function My $selector now is this (without a comma at the end), other wise I get errors: // create selector and expand with $sort value $selector = "template=child-template, limit=4 " . trim($selector, ", "); $selector .= ", sort=$sort"; Printing out the $selector while working displays: template=child-template, limit=4, branche Finally, at the end of my function, after my $pages->find($selector); I have this code for my pagination, now it uses the values: $pagination = $selects->renderPager(array( 'listMarkup' => "<ul class='MarkupPagerNav pagination'>{out}</ul>", 'currentItemClass' => 'current' )); This is now the only thing need to be adjusted: My url's at the end now look like: /pagename/page2?sort=title Not sure if /pagename/page=2/sort=title /pagename/page2/sort=title would be better, but it would be easier for the eye. Just don't know how to get the / after the page number...
horst Posted May 26, 2014 Posted May 26, 2014 "in my function ..." see scope! you need wire('input') not $input 2
Nico Knoll Posted May 26, 2014 Posted May 26, 2014 Yes, because the part behind the questionmark (in your case "?sort=titleASC") probably disappears if you're clicking a link. So you would have to add it to the pagination link as well. Didn't read the first line 1
MindFull Posted May 27, 2014 Posted May 27, 2014 Maybe I'm reading your question wrong, but maybe try manually adding a '/' in your href when rendering the pagination $pagination = $selects->renderPager(array( 'listMarkup' => "<ul class='MarkupPagerNav pagination'>{out}</ul>", 'currentItemClass' => 'current' )); echo $pagination; echo "<ul>"; foreach($selects as $select) { echo "<li><a href='{$select->url}/?sort={$sort}'>{$select->title}</a></li>"; } echo "</ul>"; echo $pagination;
bwakad Posted May 27, 2014 Author Posted May 27, 2014 Maybe I'm reading your question wrong, but maybe try manually adding a '/' in your href when rendering the pagination $pagination = $selects->renderPager(array( 'listMarkup' => "<ul class='MarkupPagerNav pagination'>{out}</ul>", 'currentItemClass' => 'current' )); echo $pagination; echo "<ul>"; foreach($selects as $select) { echo "<li><a href='{$select->url}/?sort={$sort}'>{$select->title}</a></li>"; } echo "</ul>"; echo $pagination; That's not applicable since $select in your example represents one of the pages found in my page array. The link I use is displayed on a current page, to send a ?sort=value through the browser url. The foreach comes after that link. ps. If I use /?sort= it will mean: /pagename//?sort= <<<<<<<<<<<<<<<< here it will not work... /pagename/page2/?sort= <<<<<<<<<<< this is what I need: / after the page1 or page2 etc
horst Posted May 27, 2014 Posted May 27, 2014 @bwakad: I don't understand what you are after in full, but here is a post / thread that may cover a part of it or may show an alternative way: https://processwire.com/talk/topic/5749-question-about-input-pagenum/#entry56191
bwakad Posted May 27, 2014 Author Posted May 27, 2014 Just want the slash behind the page(1). Thought is was obvious, since I mentioned it twice. I see something in the $config section: $config->pageNumUrlPrefix but that is for BEFORE the 1 as in PAGE1 and what I would like is page1/
horst Posted May 27, 2014 Posted May 27, 2014 @bwakad: yes you mentioned it, but I cannot follow your code. Also if I try to understand your answer to @Mindfull's post, I don't get it. I cannot find the link you mention there. Where is it, what does it looks like, why does it looks this way vs from where is it generated / created this way? Questions over questions for me. Sorry I cannot follow.
bwakad Posted May 27, 2014 Author Posted May 27, 2014 lol. Beginning to think I talk hebrew / turkish or something... but it's really simple. Look in my first post, the second code!!! I am talking about a link: <a href="<?php echo $page->url;?>?sort=title">Title ASC</a> (this is a link!!!) Which translates in the browser url as: http:host/pagename/?sort=title But with pagination is: http:host/pagename/page2?sort=title I am after this: http:host/pagename/page2/?sort=title And I responded to mindfull "if I use it like /?sort=title" the link will translate as: http:host/pagename//?sort=title (double slash) And with pagination is: http:host/pagename/page2/?sort=title (correct)
horst Posted May 28, 2014 Posted May 28, 2014 Great, if you have this, you only need to check your actual url for the string /page and if it matches, append a / and a ?sort= to it, and if not, only append ?sort= to it. Ready. Done! Happy coding! 1
bwakad Posted May 28, 2014 Author Posted May 28, 2014 Did not found a good way for the slash and am uncertain if rewriting url is in fact a good way. Then I tried to give the link a page name which does not exist. When I click on that I will in fact stay on the existing current page, and the browser url will display the non-existing page name after it. That's url segment ! Which was in the beginning hard to understand for me . So that will solve the issue of the slash by default, and with pagination the page(nr) stays at the end. Now I start rewriting some code to use this. But I want to thank you, for your help on the $input wire. Learned a lot.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now