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 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式