# Display URL from Page Attribute in Page List

**URL:** https://forums.concretecms.org/t/display-url-from-page-attribute-in-page-list/5800
**Category:** Developing with Concrete
**Created:** [June 23, 2023, 9:10pm UTC](https://forums.concretecms.org/t/display-url-from-page-attribute-in-page-list/5800 "2023-06-23T21:10:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![juddc](https://forums.concretecms.org/user_avatar/forums.concretecms.org/juddc/32/3655_2.png) [@juddc](https://forums.concretecms.org/u/juddc)
#### Post date: [June 23, 2023, 9:10pm UTC](https://forums.concretecms.org/t/display-url-from-page-attribute-in-page-list/5800/1 "2023-06-23T21:10:33Z")

</div>

Hi All,

I’m just wanting to have a link from a page attribute show up in a page list if one is set, and not be there if it is not.

This works but displays the URL text if an attribute isn’t set for the page. Can anyone help out? I’m not much with PHP. I’m assuming it’s some kind of If/Else?

```auto
<?php
	$url = $c->getAttribute('my_attribute');
	echo '<a href="' . $myattribute . '" target="_blank">' . 'View My Link' . '</a>';
?>
```

---

<div class="post-metadata">

### Author: ![enlil](https://forums.concretecms.org/user_avatar/forums.concretecms.org/enlil/32/3526_2.png) [@enlil](https://forums.concretecms.org/u/enlil)
#### Post date: [June 24, 2023, 9:41am UTC](https://forums.concretecms.org/t/display-url-from-page-attribute-in-page-list/5800/2 "2023-06-24T09:41:44Z")

</div>

Not sure if there wass more code to this or not. You’re using two different variables there, $url and $myattribute. This should do it for you

```auto
<?php
	if ($c->getAttribute('my_attribute') != '') {
		$url = $c->getAttribute('my_attribute');
		echo '<a href="' . $url . '" target="_blank">' . 'View My Link' . '</a>';
	}
?>

```

Edit: If your $myattribuite variable was correct keep it as is…

---

<div class="post-metadata">

### Author: ![juddc](https://forums.concretecms.org/user_avatar/forums.concretecms.org/juddc/32/3655_2.png) [@juddc](https://forums.concretecms.org/u/juddc)
#### Post date: [June 26, 2023, 7:33pm UTC](https://forums.concretecms.org/t/display-url-from-page-attribute-in-page-list/5800/3 "2023-06-26T19:33:42Z")

</div>

Hrm - I added the attribute, in this case ‘mls\_listing’. But nothing was displayed via this code.

```auto
<?php
    if ($c->getAttribute('mls_listing') != '') {
    $url = $c->getAttribute('mls_listing');
    echo '<a href="' . $url . '" target="_blank">' . 'View MLS Listing' . '</a>';
    }
?>
```

---

<div class="post-metadata">

### Author: ![enlil](https://forums.concretecms.org/user_avatar/forums.concretecms.org/enlil/32/3526_2.png) [@enlil](https://forums.concretecms.org/u/enlil)
#### Post date: [June 26, 2023, 9:33pm UTC](https://forums.concretecms.org/t/display-url-from-page-attribute-in-page-list/5800/4 "2023-06-26T21:33:44Z")

</div>

If you’re doing this in a page list, make sure you’re doing it inside the foreach ($pages as $page) loop. In this case your $c variables \*should be $page. If you could post a larger chunk of the code or send me the files I could have a closer look at what’s going on also 🙂

---

<div class="post-metadata">

### Author: ![juddc](https://forums.concretecms.org/user_avatar/forums.concretecms.org/juddc/32/3655_2.png) [@juddc](https://forums.concretecms.org/u/juddc)
#### Post date: [June 26, 2023, 10:47pm UTC](https://forums.concretecms.org/t/display-url-from-page-attribute-in-page-list/5800/5 "2023-06-26T22:47:48Z")

</div>

Ah - Yeah, that got it - It was the $c not being $page. It totally works. Thank you for your help.
