Pagelist Open Link in New Window when External link

Permalink
Hello!!

I made a code for a page list with pages on de website and External links. I want the external links opened in a new tab when checked. But it doesn't. Can somebody take a look at my code and say how I can make the link check if it's a external link?

I found this link but this doesn't work (https://www.concrete5.org/community/forums/customizing_c5/external-links-with-open-link-in-new-window-not-opening-in-new-t/#925131)

Much thanks
<?php
if(!defined('C5_EXECUTE'))
    die('Access denied');
$ih = Core::make('helper/image');
$th = Loader::helper('text'); 
$page = Page::getCurrentPage();
?>
<?php foreach($pages as $page) { ?>
  <div class="news__item">
    <a href="<?php echo $page->getCollectionLink(); ?>"></a>
    <div class="news__photo">
      <?php if($image = $page->getAttribute('news_photo')) { ?>
        <figure class="figure" style="background-image: url(<?php echo $ih->getThumbnail($image, 900, 600, true)->src; ?>)" alt="<?php echo $image->getDescription(); ?>" title="<?php echo $image->getDescription(); ?>"></figure>
      <?php } ?>
    </div>

Webvelopment
 
drbiskit replied on at Permalink Reply
drbiskit
Here you go - this should work:

<?php
if(!defined('C5_EXECUTE'))
    die('Access denied');
$ih = Core::make('helper/image');
$th = Loader::helper('text'); 
$page = Page::getCurrentPage();
?>
<?php foreach($pages as $page) {
  $target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
  $target = empty($target) ? '_self' : $target;
 ?>
  <div class="news__item">
    <a href="<?php echo $page->getCollectionLink(); ?>" target="<?php echo $target ?>">
      <div class="news__photo">
        <?php if($image = $page->getAttribute('news_photo')) { ?>
Webvelopment replied on at Permalink Reply
Webvelopment
Thank you so much!!

</a> was in the wrong place for my block but fixed it!
drbiskit replied on at Permalink Reply
drbiskit
Great - glad it worked.

Sorry I moved the </a> - I had presumed it was empty by mistake.

=0)