我有一组链接,用于显示文章列表。创建帖子时,每个链接都会输入到文本区域中。
数组的最后一项正确显示,而前三个为文章标题提取当前页面标题,当前用户以作者身份登录。标题和作者都不正确。
有任何想法吗?
$urls 数组
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>