我有一個鏈接數組,用於顯示文章列表。創建帖子時,每個鏈接都會輸入到textarea中。Loop僅正確顯示最後一項
數組的最後一項正確顯示,而前三項拉動文章標題的當前頁面標題和以作者身份登錄的當前用戶。標題和作者都不正確。
任何想法?
$網址陣列
Array (
[0] => http://localhost:8888/2013/10/custom-toothbrush-six-second-cleaning.html
[1] => http://localhost:8888/2013/10/climate-change-global-warming-al-gore.html
[2] => http://localhost:8888/2013/10/custom-toothbrush-six-second-cleaning.html
[3] => http://localhost:8888/2013/10/climate-change-global-warming-al-gore.html
)
這裏是PHP代碼
$urls=explode(PHP_EOL, get_field('publishing_articles'));
foreach($urls as $url){
$id=url_to_postid($url);
$the_title=get_the_title($id);
$author_id=get_post_field('post_author',$id);
$author_displayname=get_the_author_meta('display_name',$author_id);
$author_nicename=get_the_author_meta('user_nicename',$author_id);
echo '<li>'.$id;
echo '<a href="/author/'.$author_nicename.'" title="'.$the_title.'"><img width="50" src="/wp-content/uploads/authors/'.$author_id.'.jpg" alt="'.$author_displayname.'"/></a>';
echo '<a href="'.$url.'" title="'.$the_title.'">'.$the_title.'</a>';
echo '</li>';
}
和HTML輸出
<li>0<a href="/author/admin" title="The Future Of Light"><img width="50" src="/wp-content/uploads/authors/362.jpg" alt="admin"/></a><a href="http://localhost:8888/2013/10/custom-toothbrush-six-second-cleaning.html" title="The Future Of Light">The Future Of Light</a></li>
<li>0<a href="/author/admin" title="The Future Of Light"><img width="50" src="/wp-content/uploads/authors/362.jpg" alt="admin"/></a><a href="http://localhost:8888/2013/10/climate-change-global-warming-al-gore.html" title="The Future Of Light">The Future Of Light</a></li>
<li>0<a href="/author/admin" title="The Future Of Light"><img width="50" src="/wp-content/uploads/authors/362.jpg" alt="admin"/></a><a href="http://localhost:8888/2013/10/custom-toothbrush-six-second-cleaning.html" title="The Future Of Light">The Future Of Light</a></li>
<li>210664<a href="/author/daniela-walker" title="How Al Gore Is Making Global Warming Personal"><img width="50" src="/wp-content/uploads/authors/384.jpg" alt="Daniela Walker"/></a><a href="http://localhost:8888/2013/10/climate-change-global-warming-al-gore.html" title="How Al Gore Is Making Global Warming Personal">How Al Gore Is Making Global Warming Personal</a></li>
你可以發佈輸出的HTML的樣子 –
是否在每種情況下都顯示正確的'$ id'? – Hobo
添加HTML輸出 – ok1ha