$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Link from archive-page.php to single-page.php|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin8PV0评论

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>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far