【问题标题】:echo HTML in PHP in Wordpress在 Wordpress 中的 PHP 中回显 HTML
【发布时间】: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>

感谢您的帮助

【问题讨论】:

标签: php html wordpress echo


【解决方案1】:

the_post_thumbnail_url() 已经打印了 url。

改用 get_the_post_thumbnail_url()。

对于永久链接,使用 get_the_permalink() 代替 the_permalink()。

正如您在更新中看到的那样,它直接打印值而不是分配给变量。

如果您想使用 the_permalink() 和 the_post_thumbnail_url() 则直接在位置中使用,而不是分配给变量。

【讨论】:

    猜你喜欢
    • 2011-06-30
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    相关资源
    最近更新 更多