Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Darren Healy
seal-mask
.a{fill-rule:evenodd;}techdegree
Darren Healy
Front End Web Development Techdegree Student 23,565 Points

What is the answer.... (function to echo link to page or post within loop)?

For the life of me, I can't get this. I've reviewed the videos and I'm working along too. I've been on the functions reference page of the codex. Maybe I'm overlooking something really simple, but I just can't get the answer to this question:

"To echo out the link to a post or page within a Loop, you would use the _____________ () function."

Can someone just tell me what it is so I can look it up?

4 Answers

Mike Babb
Mike Babb
7,958 Points

the_permalink() will echo the link to the current post or page within the loop, or you can use something like "echo get_permalink(15)" to return a link to the page with an ID of 15, for example. More here: http://codex.wordpress.org/Function_Reference/get_permalink

That should be the_permalink(), Have you tried it?

Mike Babb
Mike Babb
7,958 Points

I've been working with WordPress for a while and it still catches me out occasionally. Many functions have both "the" and "get" variations, for outputting or just storing values.

Mike Babb Sometimes you would need to apply any kind of customization or sensitization on your titles or permalinks, etc.

get_.......(); allows you to store the retrieved data into a variable rather than printing it directly, So you can do what you need with it first.

That's why get_ functions exist.

Zeljko Porobija
Zeljko Porobija
11,491 Points

the_permalink() is the correct answer. get_permalink just stores the data of the link, not outputing it.