Link from archive-page.php to single-page.php

admin2025-06-02  1

I have archive-page.php, where my custom posts are displayed. I want to put a link on my image, <a href="" alt=""><img src="" alt=""></a>, which leads to single-page.php for that particular post or product. How can I do that?

I have tried this:

<a href= "<?php get_the_permalink ();?>" alt=""><img src="" alt=""></a>

but it does not work. I don't know what to put in functions.php and in those pages: archive-page.php and single-page.php

I have archive-page.php, where my custom posts are displayed. I want to put a link on my image, <a href="" alt=""><img src="" alt=""></a>, which leads to single-page.php for that particular post or product. How can I do that?

I have tried this:

<a href= "<?php get_the_permalink ();?>" alt=""><img src="" alt=""></a>

but it does not work. I don't know what to put in functions.php and in those pages: archive-page.php and single-page.php

Share Improve this question edited Dec 23, 2015 at 15:08 Gabriel 2,24810 gold badges22 silver badges24 bronze badges asked Dec 23, 2015 at 14:03 BarbaraBarbara 11 bronze badge 0
Add a comment  | 

2 Answers 2

Reset to default 1

get_the_permalink() doesn't echo anything. It just returns a string so that you can further manipulate it.

You need the_permalink() instead, which will echo the link.

The difference used to be clear in the Codex but now, in the much inferior, "developer" code reference toward which WordPress is migrating it is not so clear.

As explained by this answer,

<a href= "<?php get_the_permalink ();?>" alt=""><img src="" alt=""></a>

should be

<a href= "<?php echo get_the_permalink ();?>" alt=""><img src="" alt=""></a>

OR

<a href= "<?php the_permalink ();?>" alt=""><img src="" alt=""></a>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748836039a314124.html

最新回复(0)