2010-07-03 80 views
1

我正在構建一個最近評論的小列表,並希望鏈接到評論被放置的實際文章。不幸的是,我找不到comment_permalinkpost_permalink,所以我想也許會有一個get_permalink()函數,但再次,沒有我能找到的http://codex.wordpress.org/Function_Reference/從WordPress中的帖子ID獲取固定鏈接

單從$post->ID,我怎麼能找到該特定帖子的永久鏈接?不,這是完全必要的,但這裏是我到目前爲止有:

<?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> 

我的意圖是將$parent->post_title轉換爲永久。

回答

5

我想也許會有一個get_permalink()函數,但再次,沒有我能找到。

http://codex.wordpress.org/Function_Reference/get_permalink

我也建議你使用過get_page_link()

get_permalink()檢查後類型,並返回相應的函數的結果;

  • 頁面使用get_page_link()
  • 附件使用get_attachment_link()
  • 自定義文章類型使用get_post_permalink()
+0

有點沮喪,這個功能並沒有在[功能參考上市(HTTP://抄本.wordpress.org/Function_Reference /),但是謝謝你指出它確實存在!讓我想知道我還有什麼可能會失蹤。 – Aristotle 2010-07-04 01:24:49

1

混淆是由於模糊的函數名稱造成的。我一直在尋找一些能夠提供「帖子」鏈接的東西,卻什麼也沒有發現。出於好奇心,我偶然發現並測試了get_page_link(),結果發現它完全符合我的要求。

不幸的是,我認爲「頁面」是爲wordpress中的頁面保留的專有名詞,而不是帖子。在這種情況下,它代表了兩者。

相關問題