2013-07-28 23 views
0

我有一個Wordpress網站,我正在嘗試從特定類別獲取帖子。這有效,但現在我想鏈接到固定鏈接的具體職位。我無法讓它與foreach一起逃跑。有人能告訴我/告訴我我在這裏做錯了什麼嗎?如何在PHP的foreach中轉義?

<?php 
    global $post; // required 
    $args = array('category' => 9); // include category 9 
    $custom_posts = get_posts($args); 
    foreach($custom_posts as $post) : 
     setup_postdata($post); 
     echo "<a href='.the_permalink().'> the_title() </a> "; 
     the_excerpt(); 

//and so on.. 

    endforeach; 
?> 
+0

我不明白是什麼問題。請說明它做了什麼以及你想要做什麼。 – RiggsFolly

+0

查看@ joshtronic的回答。他理解正確。 – Johan

回答

1

你實際上並沒有正確地關閉你的報價,並沒有使用正確的功能。第5行應該更像:

the_title("<a href='".get_permalink()."'>",'</a>',true); 

BOOM。

+0

繁榮,工作就像一個魅力。謝啦!但是,你能向我解釋一下,如何將標題與逗號之間的逗號相加?我不明白...... – Johan

+1

是的,這就是'the_title()'的作用,不確定爲什麼他們不提供'get_title()'函數來補充'get_permalink()'。基本上這個函數有三個參數:'$ before','$ after'和'$ echo'。之前和之後只需要標記將打包標題和回聲告訴它,如果它離開返回字符串或立即回聲。只是一個WP事情真的:http://codex.wordpress.org/Function_Reference/the_title – joshtronic

+0

http://codex.wordpress.org/Function_Reference/the_title – RiggsFolly