dswm97353 2012-11-20 23:03
浏览 13
已采纳

获取帖子/页面URL - Wordpress

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?

Thanks dvent

  • 写回答

1条回答 默认 最新

  • dtja73027 2012-11-20 23:22
    关注

    Wordpress provides a method for that : the_permalink();

    Look at http://codex.wordpress.org/The_Loop.

    You can also use the get_permalink($id) method. http://codex.wordpress.org/Function_Reference/get_permalink

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧