I’m building a small list of recent comments, and would like to make links to the actual posts that the comments were placed on. Unfortunately, there is no comment_permalink
or post_permalink
that I can find, so I thought maybe there would be a get_permalink()
function, but again, none that I could find on http://codex.wordpress.org/Function_Reference/.
From the $post->ID
alone, how can I find the permalink for that particular post? Not that it’s completely necessary, but here is what I have so far:
<?php $comments = get_comments( array( 'status'=>'approve', 'number'=>5 ) ); ?>
<p class="recently-posted-comments">Recent Comments</p>
<ul>
<?php foreach ($comments as $comment): $parent = get_post($comment->comment_post_ID); ?>
<li><?php print $comment->comment_author; ?>
on <?php print $parent->post_title; ?></li>
<?php endforeach; ?>
</ul>
My intent is to convert the $parent->post_title
into a permalink.
http://codex.wordpress.org/Function_Reference/get_permalink
I’d also recommend using that over
get_page_link()
get_permalink()
checks the post type and returns the result of the appropriate function;get_page_link()
get_attachment_link()
get_post_permalink()
The confusion comes as a result of ambiguous function names. I was looking for something that suggested a link for a “post,” yet found nothing. Out of curiousity, I came across and tested
get_page_link()
, only to find that it does exactly what I was looking for.Unfortunately I assumed that “page” was an exclusive term reserved for pages in wordpress, rather than posts. It appears in this context it is representative of both.