php 获取帖子/页面 URL - Wordpress
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13483732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get Post / Page URL - Wordpress
提问by dvent
I have the following code
我有以下代码
<div id="featured-posts" class="container_12">
<?php
global $post;
$myposts = get_posts('numberposts=3&category=12');
foreach($myposts as $post) :
?>
<?php global $post; ?>
<?php
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' );
?>
<?php
$colors = array("#000000", "#949c51", "#571c1e", "#f36533", "#782a80", "#f6a41d", "#ed1b24");
$randomColor = $colors[array_rand($colors)];
?>
<a href="LINK OF THE POST"><div class="grid_4 featured-home" style="background: url(<?php echo $src[0]; ?> ) !important;">
<div class="featured-details" style="border-color: <?php echo $randomColor; ?>;">
<h2 style="color: <?php echo $randomColor; ?>;"><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
<div class="featured-lower" style="border-color: <?php echo $randomColor; ?>;"></div>
</div></a>
<?php endforeach; ?>
</div>
This takes the most recent 3 posts, in category 12 and displays them in a div. I want this whole div to link to the post. You'll see where it says LINK OF THE POST. Can anyone help me get the URL in here?
这需要最新的 3 个帖子,在类别 12 中,并将它们显示在一个 div 中。我希望整个 div 链接到帖子。你会看到它在哪里说LINK OF THE POST。谁能帮我得到这里的网址?
Thanks dvent
谢谢 dvent
回答by kketch
Wordpress provides a method for that : the_permalink();
Wordpress 提供了一种方法:the_permalink();
Look at http://codex.wordpress.org/The_Loop.
查看http://codex.wordpress.org/The_Loop。
You can also use the get_permalink($id) method. http://codex.wordpress.org/Function_Reference/get_permalink
您还可以使用 get_permalink($id) 方法。 http://codex.wordpress.org/Function_Reference/get_permalink

