Jump to content

<a> tag causing Internal Server Error


ngrmm
 Share

Recommended Posts

there is a pagination (next|prex) at the end of the page
i want to hide next on the last page of the siblings and hide prev on the first

<?php
if($page != $pages->get(1019)->children->first()) {
  echo "<a class='link prev' href="$page->prev->url">";

    foreach($page->prev->image as $image) {
        $thumb = $image->height(60);
        echo "<div><img src='$thumb->url'/></div>"; 
        }
    $test = $page->prev;
    echo "<span> $test->title </span>";
    echo "<span class='date' > $test->teaser_date </span>";
    }
    
  echo '</a>'

if($page != $pages->get(1019)->children->last()) {
  echo "<a class='link next' href="$page->next->url">";
    
    foreach($page->next->image as $image) {
        $thumb = $image->height(60);
        echo "<div><img src='$thumb->url'/></div>"; 
        }
    $test = $page->next;
    echo "<span> $test->title </span>";
    echo "<span class='date' > $test->teaser_date </span>";
    }
    
  echo "</a>";
  
?>

line 3: echo "<a class='link prev' href="$page->prev->url">"; is causing the error but i don't know why

Link to comment
Share on other sites

It's a syntax error.

// This is without the syntax error (note the dots and the single quotes)
echo "<a class='link prev' href='" . $page->prev->url . "'>";
BTW:
// Potential memory hog
$pages->get(1019)->children->first()

// This doesn't need to preload all children. The property boolean `true` is to count only the visible.
$pages->get(1019)->numChildren(true)
  • Like 5
Link to comment
Share on other sites

thanks Marttijn

i edited the code but still getting Internal Error

there are always at least 3 children of that page (1019). and all of them aren't hidden.

 

	<div class="pagination">
	<?php
	$prevPage = $page->prev;
	$nextPage = $page->next; 

	if($page != $pages->get(1019)->children->first()) {
 				
		echo "<a class='link prev' href='" . $prevPage->url . "' >"
		
 			foreach($prevPage->image as $image) {
				$thumb = $image->height(60);			
	    		        echo "<div><img src='" . $thumb->url . "'/></div>"; 
    		                }
		
			echo "<span>".  $prevPage->title ."</span>";
			echo "<span class='date' >".  $prevPage->teaser_date ."</span>";
   		
   		echo "</a>"
   		
   		}

	if($page != $pages->get(1019)->children->last()) {		
		echo "<a class='link next' href='" . $nextPage->url . "' >"
		
	 		foreach($nextPage->image as $image) {
				$thumb = $image->height(60);	 		
		    	        echo "<div><img src='" . $thumb->url . "'/></div>"; 
   		 	        }
		
			echo "<span>". $nextPage->title ."</span>";
			echo "<span class='date' >". $nextPage->teaser_date ."</span>";
		
		echo "</a>"
   		}
   		?>
   		
	</div>

Link to comment
Share on other sites

@ngrmm: take a closer look at the code Martijn posted and note the semicolon. Looks like your code is still missing that.

While developing a site, you should run it in debug mode. This will output errors on screen and make it a lot easier to spot the source of issues like these.

  • Like 3
Link to comment
Share on other sites

@teppo thanks

here the final code:

 

	<div class="pagination">
	<?php
	$prevPage = $page->prev;
	$nextPage = $page->next; 
	if($page != $pages->get(1019)->children->first()) {
		echo "<a class='link next' href='" . $prevPage->url . "' >";		
 			foreach($prevPage->image as $image) {
				$thumb = $image->height(60);			
	    		        echo "<div><img src='" . $thumb->url . "'/></div>"; 
    			        }
			echo "<span>". $prevPage->title ."</span>";
			echo "<span class='date' >". $prevPage->teaser_date ."</span>";
   		echo "</a>";
   		}
	if($page != $pages->get(1019)->children->last()) {		
		echo "<a class='link prev' href='" . $prevPage->url . "' >";
	 		foreach($nextPage->image as $image) {
				$thumb = $image->height(60);	 		
		    	        echo "<div><img src='" . $thumb->url . "'/></div>"; 
   		 		}		
			echo "<span>". $nextPage->title ."</span>";
			echo "<span class='date' >". $nextPage->teaser_date ."</span>";
		echo "</a>";
   		}
   		?>
	</div>
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By PensiveOwl
      Hello,
      Today I was playing around with one of my old websites. Specifically with http and https redirection through cPanel as I parked and redirected a new domain on top of the current one.
      I  was able to see the home page and the website fully working.  I noticed that my current domain wasn't redirected properly as I could see the website as either http or https on all pages. I know I could have added a code to htaccess  file to achieve that, I just wasn't sure how was the Processwire initially configured and set up. Last time I did any updates was more than 2 years ago.
      So I decided to check the processwire admin setup. Tried to log into my admin panel (using my custom admin login url/page) but nothing happened. Blank page. I simply could not access it. 
      Then all of sudden I received that scary "Internal Server Error" :

      " Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.
      Error has been logged. Administrator has been notified." 
      Now my first instinct was to check the .htaccess file. But no matter what I did (modifying, restoring from backup, deleting) nothing happened.
      Then I went to site/config.php file and updated the $config->debug = true;  (instead of false) to see the error messages.
      Here we go: 
      "
      Fatal error: Class 'ProcessWire\InputfieldText' not found in /home/edwbst/public_html/wire/modules/Inputfield/InputfieldPassword/InputfieldPassword.module on line 17
      Warning: class_parents(): Class InputfieldPassword does not exist and could not be loaded in /home/edwbst/public_html/wire/core/Functions.php on line 804
      Warning: in_array() expects parameter 2 to be array, boolean given in /home/edwbst/public_html/wire/core/Functions.php on line 805
      "
      My web host is using the PHP Version 7.0.26, MariaDB 10.1.28 , and I believe the Processwire version used is from September 2015. 

      I'd appreciate any insights on this error.
      Thank you!
      Ian
    • By JMH
      Hi all,
      I'm trying to upload an image to a blog post. The ProcessWire blog editing page is relatively simple. See attached. When I try to add more images and publish the post an internal server error is returned and a blank space is where the additional images should be. 
      Can anyone advise on how this can be resolved quickly.
      Please let me know any additional information you'd need. 
      Many thanks.
      JMH 
       


    • By ngrmm
      i use a textarea-field with CKEditor. its filled with text which has a link.
      this field is in two of my templates. the first template is an article and everything is finde. the second is an index-template and textarea is placed inside a link. this causes problems.

      index-template looks like this
      <a href=""> … <?php echo $page->textarea;  ?> … </a> which results in:
      <a href=""> <p>Lorem Ipsum <a href"">Test</a></p> </a>
      is there a way to output this textarea wihtout the <a> links? i don't need the link on my index-template
    • By Rachid Finge
      I'm building a smartphone app that allows users to record a voice clip and send it to our server, which runs ProcessWire. Files are sent over HTTPS Post, currently without any sort of authentication.
      I've succeeded using the WireUpload class to fetch the uploaded file from the $_FILES super global. Where I get in trouble is when I try to add the audio file to the audio page, where there's an Input field called 'audiofile'. Whenever I try to use any file related method, an Internal Server Error occurs.
      Here's my code, which runs in the page's template.
      <?php Header("Content-Type: text/plain"); $upload_path = $config->paths->assets . "files/audio/"; $u = new WireUpload('files'); $u->setMaxFiles(1); $u->setOverwrite(false); $u->setValidExtensions(array('mp3', 'mp4', 'm4a')); $u->setDestinationPath($upload_path); // I can confirm through my FTP client that the file sent through POST actually shows up in the $upload_path location. $fileresult = $u->execute(); // This is the File input field in my template. Doing print_r($audiofield) confirms this is an existing object. $audiofield = $fields->get("audiofile"); // Trying this for the heck of it, but all that results is HTTP 500. $audiofield->deleteAll(); foreach($fileresult as $filename) { // I've seen various examples on what to do now. Here's one that causes a 500 error. $page->'audiofile' = $upload_path . $filename; // This seems the most logical thing to do, but also causes HTTP 500. $audiofield->add($upload_path . $filename); // Unlinking succeeds (given that I comment out the lines that cause the HTTP 500 errors) unlink($upload_path . $filename); } // We never get to this phase. $page->save(); ?> Things of note:
      Server runs PHP 5.4.4-14+deb7u8 on Debian with Apache/2.2.22.  File uploading through the admin on the audio page works without issues, also when uploading multiple files at once or sequentially. I've confirmed the owner of $upload_path to be www-data and its permissions to be 755. What's the final step I'm missing to add the audio file to the input field on my page?
    • By benjaminE
      Hello,
      I was having some trouble installing modules (they weren't showing up in the module manager) and so I deleted the contents of the folder site > assets > cache in the hope of fixing this problem.
      However, having done this any page I try to navigate to on the site (including the root /index.php) throws up a 500 Internal Sever Error.
      Does anyone have any idea about what might have gone wrong here? It's slightly worrying...
      Many thanks in advance for any help.
      b
×
×
  • Create New...