php – WordPress:如何将the_title显示为链接
发布时间:2020-12-13 21:50:56 所属栏目:PHP教程 来源:网络整理
导读:我在将标题显示为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 'u
我在将标题显示为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>'; 它将显示标题,但不显示链接. 有任何想法吗?我们将不胜感激. 日Thnx! 解决方法
the_title输出内容本身.你需要使用get_the_title()
试试这个: echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>'; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |