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

×
×
  • Create New...