【发布时间】:2014-04-06 14:35:54
【问题描述】:
我无法在 WordPress 函数中将标题显示为链接。
如果我这样编码:
function my_popular_posts($count) {
$query = new WP_Query( array(
'orderby' => 'comment_count',
'order' => 'DESC',
'posts_per_page' => $count));
if($query->have_posts()) {
echo '<ul>';
while($query->have_posts()) : $query->the_post();
**THIS LINE --> echo '<li><a href='.get_permalink().'> .the_title(). </a></li>';
endwhile;
echo '</ul>';
} else {
echo "<p>No popular posts found<p>";
}
}
在运行时,链接显示为“.the_title()”
如果我这样编码:
echo '<li><a href='.get_permalink().'>'.the_title().'</a></li>';
它将显示标题,但不会显示为链接。
有什么想法吗?您的帮助将不胜感激。
谢谢!
【问题讨论】:
-
@cale_b 您的回答部分正确。在我的一次编辑中,我有双引号,但有些我忘了把它们放回去。这是正确的答案:stackoverflow.com/a/22182574/742030
-
the_title() 是自回显的,它会自己回显,所以当在回显中使用时它会中断,如果在回显语句中使用,请使用
get_the_title()。