Php 如何在循环中获取当前WordPress帖子的链接?
下面是我的循环:Php 如何在循环中获取当前WordPress帖子的链接?,php,wordpress,Php,Wordpress,下面是我的循环: <?php if (have_posts()): // This function belowm is responsible for iterating through the posts while (have_posts()): the_post(); ?> <div class="col-md-4"> <h3><?php the_title(); ?&g
<?php if (have_posts()):
// This function belowm is responsible for iterating through the posts
while (have_posts()): the_post(); ?>
<div class="col-md-4">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<?php get_post_permalink(); ?>
<?php edit_post_link(); ?>
</div>
<?php
endwhile; ?>
<?php
endif; ?>
Get
应显示链接,但这是正在呈现的内容。它没有显示帖子的永久链接
如果你想获得Post Permalink,你应该使用
get\u Permalink($Post\u id)
请尝试以下方法:
<?php if (have_posts()):
// This function belowm is responsible for iterating through the posts
while (have_posts()): the_post();
$id = get_the_ID();
?>
<div class="col-md-4">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<?php get_the_permalink($id); ?>
<?php edit_post_link(); ?>
</div>
<?php
endwhile; ?>
<?php
endif; ?>
其他答案都不正确
get\u the_permalink()
(您也可以使用get\u permalink()
,因为它是一个别名)返回数据,而不是ECHO。因此,它永远不会被打印到屏幕上(大多数带有get\ucode>前缀的WP函数都是这样工作的。)
您有两个选择:
使用get_permalink(get_the_ID())
传递当前帖子ID(如果不在循环中)并回显它
使用
permalink(),它将回显permalink(在循环中)李>
永久链接()
:
这将回显URL,但不会使链接可点击-您需要将其添加到返回“post permalink.”,但返回:“如果post不存在,则返回permalink URL或false”。另外,您应该在发布问题之前检查文档。。。我如何获得到帖子的链接?
<?php if (have_posts()):
// This function belowm is responsible for iterating through the posts
while (have_posts()): the_post(); ?>
<div class="col-md-4">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<?php the_permalink(); ?>
<?php edit_post_link(); ?>
</div>
<?php
endwhile; ?>
<?php
endif; ?>
<?php if (have_posts()):
// This function belowm is responsible for iterating through the posts
while (have_posts()): the_post(); ?>
<div class="col-md-4">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<?php echo get_permalink(); ?>
<?php edit_post_link(); ?>
</div>
<?php
endwhile; ?>
<?php
endif; ?>
<?php if (have_posts()):
// This function belowm is responsible for iterating through the posts
while (have_posts()): the_post(); ?>
<div class="col-md-4">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<a href="<?php the_permalink(); ?>">Click Here</a>
<?php edit_post_link(); ?>
</div>
<?php
endwhile; ?>
<?php
endif; ?>