Skip to content

Commit

Permalink
Merge pull request #25 from DekodeInteraktiv/iss24-external-links
Browse files Browse the repository at this point in the history
Add class if link url is external
  • Loading branch information
trinef committed May 7, 2018
2 parents e94c0c3 + aad51ae commit b81305f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.1.5
* Add class to list item if link is external

## 1.1.4
* Dynamic content can list terms in a taxonomy
* Dynamic content can limit posts to a set category
Expand Down
4 changes: 3 additions & 1 deletion assets/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
<ul class="<?php echo esc_attr( $list_classes ); ?>">
<?php
foreach ( $items as $item ) {
printf( '<li class="%s">', esc_attr( $list_li_classes ) );
$list_li_class_ext = isset( $item['external'] ) && true === $item['external'] ? ' hogan-linklist-item-external' : '';

printf( '<li class="%1$s%2$s">', esc_attr( $list_li_classes ), esc_attr( $list_li_class_ext ) );
printf( '<a%s>',
hogan_attributes( [
'href' => $item['href'],
Expand Down
14 changes: 8 additions & 6 deletions class-linklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,10 @@ public function get_list_items( array $list ) : array {
$menu = $list['predefined_list'];
foreach ( wp_get_nav_menu_items( $menu ) as $link ) {
$items[] = [
'href' => $link->url,
'target' => $link->target,
'title' => $link->title,
'href' => $link->url,
'target' => $link->target,
'title' => $link->title,
'external' => strpos( $link->url, home_url() ) === false,
];
}
break;
Expand All @@ -287,9 +288,10 @@ public function get_list_items( array $list ) : array {
}

$items[] = [
'href' => $item['link']['url'],
'target' => $item['link']['target'],
'title' => hogan_get_link_title( $item['link'] ),
'href' => $item['link']['url'],
'target' => $item['link']['target'],
'title' => hogan_get_link_title( $item['link'] ),
'external' => strpos( $item['link']['url'], home_url() ) === false,
];
}
break;
Expand Down
2 changes: 1 addition & 1 deletion hogan-linklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://github.com/dekodeinteraktiv/hogan-linklist
* GitHub Plugin URI: https://github.com/dekodeinteraktiv/hogan-linklist
* Description: Link List Module for Hogan
* Version: 1.1.4
* Version: 1.1.5
* Author: Dekode
* Author URI: https://dekode.no
* License: GPL-3.0-or-later
Expand Down

0 comments on commit b81305f

Please sign in to comment.