我認爲這個問題是PHP的,而不是WordPress的...如何在鏈接中包裝foreach循環項目?
我的輸出,其使用特定的WordPress頁面模板的頁面代碼塊:
$pages = get_pages(array(
'meta_key' => '_wp_page_template',
'meta_value' => 'page-product.php'
));
foreach($pages as $page){
echo $page->post_title.'<br />';
}
我的問題是我怎麼換行post_title鏈接(the_permalink()到頁面本身)?
'echo'
這不行。 get_the_permalink必須在循環中使用。 get_pages將返回一個post對象數組。你必須使用get_permalink並傳入post對象。 –
我在回答中使用了get_page_link。 WordPress的實際wordpress文檔中引用實現用戶問題的方式。 –