【问题标题】:Link to post's ID (Wp)链接到帖子的 ID (Wp)
【发布时间】:2013-04-06 22:02:31
【问题描述】:

我无法链接到单个帖子。我已经查询了我的循环以显示与 slug 匹配的帖子类别。所以我只需要一个图库模板。

这对我来说是个问题,这意味着我不能简单地使用get_permalink()

我的代码如下,但不起作用。有什么想法吗?

<div id="tile-container">
<?php query_posts(array('category_name' => $post->post_name));?>

<?php while (have_posts()) : the_post(); ?>

  <?php

    $link = the_permalink( $post->ID );

    echo '<div class="tile-posts">';
    echo '<a href="' . echo $link . '">';
      the_content();
    echo '</a>"';
    echo '</div>';

  ?>


  <?php endwhile; ?>

  <?php wp_reset_query(); ?>
</div>

【问题讨论】:

    标签: wordpress post categories slug permalinks


    【解决方案1】:

    你可以试试the_permalink()

    http://codex.wordpress.org/Function_Reference/the_permalink

    或者您也可以使用$post-&gt;post_name引用帖子网址

    我也注意到了这一点:

    echo '<a href="' . echo get_permalink($link) . '">';
    

    由于您已经将$link 分配给上面的get_permalink() 方法,因此您不需要将$link 作为参数传递给get_permalink() - 您应该能够像这样回显它

    echo '<a href="' . $link . '">';
    

    【讨论】:

    • 是的 - 我已经看过所有的代码 - 看看我的答案应该会有所帮助
    • 我试过了,但它在我的画廊中显示空白页。计划是链接到显示 single.php 的帖子
    • 链接是在html中输出的吗?只是链接锚文本是空白的吗?
    • 如果我只使用 the_permalink() 它会转到图像 url。使用上面的代码,您建议画廊页面实际上是空白的。白页
    • $post->post_name));?> ID ); echo '
      '; echo '';内容(); echo '"'; echo '
      '; ?>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多