2

im trying to build a blogsite with wordpress and im trying to show a clickable picture with a link.

            <?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();
            }

           ?>

I think the echo does not work :/
The result is this:

<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>

Thanks for helping

3

1 Answer 1

2

the_post_thumbnail_url() already prints the url.

Use get_the_post_thumbnail_url() instead.

Again for permalink, use get_the_permalink() instead of the_permalink().

As you can see in your update, it directly prints the values instead of assigning into the variables.

If you want to use the_permalink() & the_post_thumbnail_url() then use directly in the location instead of assigning into a variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.