wordpress中能够调用某篇文章的链接的方法有:the_permalink和get_permalink
the_permalink() 显示当前文章或页面的链接
get_permalink() 返回当前文章或页面的链接
1 | This address for this post is: <?php the_permalink(); ?> |
1 | <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> |
the_permalink() 函数的代码位于 wp-includes/link-template.php.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /** * Display the permalink for the current post. * * @since 1.2.0 */ function the_permalink() { /** * Filter the display of the permalink for the current post. * * @since 1.5.0 * * @param string $permalink The permalink for the current post. */ echo esc_url( apply_filters( 'the_permalink', get_permalink() ) ); } |
the_permalink(),获取并显示文章的永久链接(固定链接,不是指短链接),实际上相当于echo get_permalink(),在使用时像其他的wordpress函数一样可以用某篇文章的ID作为参数,以获取该文章的链接。
比较:the_permalink和get_permalink方法适合模板制作,随着后台固定链接形式的变化而变化。