biber Posted May 16, 2015 Share Posted May 16, 2015 Hi, I'm still a newbie on PW and not very familiar with the syntax. I have set up a gallery page and now I try to give it two links to sort the images by two different fields belonging to every image. This fields I have created with the ImageExtra Module: Name_1 contains the year, Name_2 contains the place. Now I put in a link <sort by name_1> and a link <sort by name_2> This should work with urlSegment2 (urlSegment1 I use to show a specific image) <?php // output 'headline' if available, otherwise 'title' echo '<h1>' . $page->get('headline|title') . '</h1>'; // galerie.php template file // overview - and single image view //get all segments and clean segments! $seg1 = $sanitizer->pageName($input->urlSegment1); $seg2 = $sanitizer->pageName($input->urlSegment2); $seg3 = $sanitizer->pageName($input->urlSegment3); // Links zur Sortierung: echo 'Sortierung nach <a href="'.$input->post(urlSegment2 = 1).'">Name 1</a> '; echo '<a href="'.$input->post(urlSegment2 = 2).'">Name 2</a> '; //check for the second urlsegment sort order // sortiere nach name_1: if ($seg2 = 1) {$images = $page->images->sort("name_1");} // sortiere nach name_2: elseif ($seg2 = 2) {$images = $page->images->sort("name_2");} else {} //check for the third urlsegment not needed if ($seg3) { // unknown URL segment, send a 404 throw new Wire404Exception(); } //normal content without first url segment! if (!$seg1) { // output bodycopy echo $page->body; // output images foreach($images as &$image) { $thumbnail = $image->height(100); echo '<div class="rahmen"><a href="'.$page->url . $image.'"><img class="shadow" src="'.$thumbnail->url.'" alt="'.$thumbnail->caption.'" title="'.$image->caption.'"></a></div>'; } } //special view output with an url segment... if ($seg1) { // get the image in the correspondent position: $index = $input->$seg1; $image = $page->images->index($index); // Link zum vorigen Bild: echo '<a href="'.$images->getPrev($images->$seg1).'"><img src="'.$config->urls->site.'templates/styles/links.gif" title="voriges Bild"></a> '; // Link zur Thumbnail-Seite: echo '<a href="'.$page->url.'"><img src="'.$config->urls->site.'templates/styles/index.gif" title="zurück zur Übersicht"></a> '; // Link zum nächsten Bild: echo '<a href="'.$images->getNext($images->$seg1).'"><img src="'.$config->urls->site.'templates/styles/rechts.gif" title="nächstes Bild"></a><br />'; // Bild zeigen: echo '<img class="shadow" src="'.$image->url . $seg1.'" alt="'.$images->$seg1->description.'" title="'.$images->$seg1->description.'">'; // Textfelder zu den Bildern anzeigen: echo '<h3>'.$images->$seg1->caption.'</h3>'; echo '<p>'. $images->$seg1->description. '<br />' .$images->$seg1->name_1.' ' .$images->$seg1->name_2.'</p>'; } ?> I get a syntax error: unexpected '=' in line 15. Perhaps someone can help me. Thanx in advance Günter Link to comment Share on other sites More sharing options...
tpr Posted May 16, 2015 Share Posted May 16, 2015 You should put "==" here I guess: if ($seg2 = 1) elseif ($seg2 = 2) And what is your goal here? $input->post(urlSegment2 = 1) Link to comment Share on other sites More sharing options...
adrian Posted May 16, 2015 Share Posted May 16, 2015 Line 15 and 16 will need to be changed. You just want: $input->urlSegment2 You don't want the "post" and you can't use "=" where you have it, hence the syntax error. EDIT: Oops - tpr beat me! Link to comment Share on other sites More sharing options...
biber Posted May 16, 2015 Author Share Posted May 16, 2015 Hi, many thanks for Your fast replies! I have changed the lines 15 and 16 and the error disappears, but how do I tell PW which order I want? You may have a look at the site: http://malabu.de/pw/kindheit/ Günter Link to comment Share on other sites More sharing options...
tpr Posted May 16, 2015 Share Posted May 16, 2015 For example, set your links like this: kindheit/?order=1 kindheit/?order=2 and then set the order in your template file with $sanitizer->name($input->get->order) 1 Link to comment Share on other sites More sharing options...
biber Posted May 18, 2015 Author Share Posted May 18, 2015 @ tpr: Thanks for your hint, it helped me to sort my thumbnails. But if I call a single image the order vanishes. I've tried to put the order-variable in the foreach-loop, but this did not work with the getNext and getPrev function. This is one page: http://malabu.de/pw/kindheit/ and here comes my current template file: <?php // output 'headline' if available, otherwise 'title' echo '<h1>' . $page->get('headline|title') . '</h1>'; //get all segments and clean segments! $seg1 = $sanitizer->pageName($input->urlSegment1); $seg2 = $sanitizer->pageName($input->urlSegment2); $seg3 = $sanitizer->pageName($input->urlSegment3); //check for the second urlsegment not needed if ($seg2) { // unknown URL segment, send a 404 throw new Wire404Exception(); } //check for the third urlsegment not needed if ($seg3) { // unknown URL segment, send a 404 throw new Wire404Exception(); } // Sortierung übernehmen: $order = $input->get->order; // Links zur Sortierung: echo '<p>Sortierung nach <a class="tab" href="'.$page->url.'?order=1">Name 1</a> <a class="tab " href="'.$page->url.'?order=2">Name 2</a></p>'; // sortiere nach name_1: if ($order == 1) { $images = $page->images->sort("name_1"); } // sortiere nach name_2: elseif ($order == 2) { $images = $page->images->sort("name_2"); } // ohne Sortierung: else {} $images = $page->images; //normal content without first url segment! if (!$seg1) { // output bodycopy echo $page->body; // output images foreach($images as &$image) { $thumbnail = $image->height(100); echo '<div class="rahmen"><a href="'.$page->url . $image.'"><img class="shadow" src="'.$thumbnail->url.'" alt="'.$thumbnail->caption.'" title="'.$image->caption.'"></a></div>'; // try to keep the order-variable: // echo '<div class="rahmen"><a href="'.$page->url . $image.'/?order='.$order.'"><img class="shadow" src="'.$thumbnail->url.'" alt="'.$thumbnail->caption.'" title="'.$image->caption.'"></a></div>'; } } //special view output with an url segment... if ($seg1) { // get the image in the correspondent position: $index = $input->$seg1; $image = $page->images->index($index); // Link zum vorigen Bild: echo '<a href="'.$images->getPrev($images->$seg1).'"><img src="'.$config->urls->site.'templates/styles/links.gif" title="voriges Bild"></a> '; // Link zur Thumbnail-Seite: echo '<a href="'.$page->url.'"><img src="'.$config->urls->site.'templates/styles/index.gif" title="zurück zur Übersicht"></a> '; // Link zum nächsten Bild: echo '<a href="'.$images->getNext($images->$seg1).'"><img src="'.$config->urls->site.'templates/styles/rechts.gif" title="nächstes Bild"></a><br />'; // Bild zeigen: echo '<img class="shadow" src="'.$image->url . $seg1.'" alt="'.$images->$seg1->description.'" title="'.$images->$seg1->description.'">'; // Textfelder zu den Bildern anzeigen: echo '<h3>'.$images->$seg1->caption.'</h3>'; echo '<p>'. $images->$seg1->description. '<br />' .$images->$seg1->name_1.' ' .$images->$seg1->name_2.'</p>'; } ?> Can anyone help me with the correct syntax? Günter Link to comment Share on other sites More sharing options...
tpr Posted May 18, 2015 Share Posted May 18, 2015 You should save the order to session, see https://processwire.com/api/variables/session/ Thus the order will be always available in "$session->itemOrder" (or whatever you name it). For prev-next links, I assume you should use this: http://cheatsheet.processwire.com/page/built-in-methods-reference/page-next-pagearray/ Here you will need to set the order again in the $pageArray (here you can use $session->itemOrder). I have no experience with this so maybe I'm wrong. Link to comment Share on other sites More sharing options...
biber Posted May 26, 2015 Author Share Posted May 26, 2015 Thanks for your help. I have now realized my gallery with a combination of url-segment (for choosing the image to enlarge) and get-procedure (for to change the order of the images). Don't know, if this ist the best way to do it, but it works for me, and I understand, what I have done. Here is the template to my site http://malabu.de/pw: <?php include('./_head.php'); // include header markup ?> <div id='index'> <?php // output 'headline' if available, otherwise 'title' echo '<h1>' . $page->get('headline|title') . '</h1>'; //get all segments and clean segments! $seg1 = $sanitizer->pageName($input->urlSegment1); $seg2 = $sanitizer->pageName($input->urlSegment2); $seg3 = $sanitizer->pageName($input->urlSegment3); //check for the second urlsegment not needed if ($seg2) { // unknown URL segment, send a 404 throw new Wire404Exception(); } //check for the third urlsegment not needed if ($seg3) { // unknown URL segment, send a 404 throw new Wire404Exception(); } // Sortierung übernehmen: $order = $input->get->order; // sortiere nach name_: if ($order >0) { $images = $page->images->sort("name_".$order); $session->set($order, $order); } // ohne Sortierung: else { $images = $page->images; } //normal content without first url segment! if (!$seg1) { // output bodycopy echo $page->body; // Links zur Sortierung: echo '<p>Sortierung nach <a class="tab" href="'.$page->url.'?order=1">'. $page->get('name_1').'</a> <a class="tab " href="'.$page->url.'?order=2">'. $page->get('name_2').'</a></p>'; // output images foreach($images as &$image) { $thumbnail = $image->height(100); echo '<div class="rahmen"><a href="'.$page->url . $image.'?order='.$session->get($order).'"><img class="shadow" src="'.$thumbnail->url.'" alt="'.$thumbnail->caption.'" title="'.$image->caption.'"></a></div>'; } } //special view output with an url segment... if ($seg1) { // get the image in the correspondent position: $index = $input->$seg1; $image = $page->images->index($index); // Link zum vorigen Bild: echo '<a href="'.$images->getPrev($images->$seg1).'?order='.$session->get($order).'"><img src="'.$config->urls->site.'templates/styles/links.gif" title="voriges Bild"></a> '; // Link zur Thumbnail-Seite: echo '<a href="'.$page->url.'?order='.$session->get($order).'"><img src="'.$config->urls->site.'templates/styles/index.gif" title="zurück zur Übersicht"></a> '; // Link zum nächsten Bild: echo '<a href="'.$images->getNext($images->$seg1).'?order='.$session->get($order).'"><img src="'.$config->urls->site.'templates/styles/rechts.gif" title="nächstes Bild"></a><br />'; // Bild zeigen: echo '<img class="shadow" src="'.$images->url . $seg1.'" alt="'.$images->$seg1->description.'" title="'.$images->$seg1->description.'">'; // Textfelder zu den Bildern anzeigen: echo '<h3>'.$images->$seg1->caption.'</h3>'; echo '<p>'. $images->$seg1->description. '<br />'.$images->$seg1->name_1.' '.$images->$seg1->name_2.'</p>'; } ?> </div><!-- end content --> <?php include('./_foot.php'); // include footer markup ?> If anyone knows to make it better, I'd like to hear about ... Link to comment Share on other sites More sharing options...
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