【发布时间】:2017-09-11 01:42:17
【问题描述】:
我正在尝试使用 wordpress 构建一个博客网站,并且我正在尝试显示带有链接的可点击图片。
<?php
$counter = get_posts();
$i = 0;
while ($i < count($counter)) {
$args = array( 'posts_per_page' => 1,'offset' => $i );
$i = $i + 3;
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) :
setup_postdata( $post );
$permalink = the_permalink();
$thumbnail = the_post_thumbnail_url();
echo '<a href="'.$permalink.'"><img src="' . $thumbnail . '"> </img></a>';
/*the_post_thumbnail();*/
endforeach;
wp_reset_postdata();
}
?>
我认为回声不起作用:/
结果是这样的:
<div class="col span_1_of_3">
This is column 1 http://lena.sbstn.net/2017/04/14/ein-neuer-post/http://lena.sbstn.net/wp-content/uploads/2017/01/22.jpg
<a href=""> <img src=""> </a>http://lena.sbstn.net/2017/01/29/new-york-cheesecake/http://lena.sbstn.net/wp-content/uploads/2017/01/image2-525x700.jpg
<a href=""> <img src=""> </a>
</div>
感谢您的帮助
【问题讨论】:
-
您需要将实际输出放在这里,而不是屏幕上呈现的 html。
-
@TurtleTread 我编辑了问题:) 谢谢! (但我不明白输出..)
-
在此处查看如何使用这些功能。 codex.wordpress.org/Function_Reference/the_permalink。还有developer.wordpress.org/reference/functions/get_permalink,如果你想得到一个返回值而不是直接回显它。