Php 如何获取自定义文章类型的标题作为其相关文章的链接?
我想获取自定义帖子类型的帖子标题,并将其链接到相关帖子。 所以我得到了以下代码:Php 如何获取自定义文章类型的标题作为其相关文章的链接?,php,html,wordpress,Php,Html,Wordpress,我想获取自定义帖子类型的帖子标题,并将其链接到相关帖子。 所以我得到了以下代码: query_posts( 'post_type=custom_post_type&posts_per_page=1&order=DESC' ); while (have_posts()) : the_post(); echo "' >"; the_title(); ""; endwhile; 文章标题的输出工作正常,但链接不正确。 我有语法错误吗?还是这种方法完全错误 谢谢你的帮助 使用g
query_posts( 'post_type=custom_post_type&posts_per_page=1&order=DESC' );
while (have_posts()) : the_post();
echo "' >"; the_title(); "";
endwhile;
文章标题的输出工作正常,但链接不正确。
我有语法错误吗?还是这种方法完全错误
谢谢你的帮助 使用get_permalink()
获取当前$post
的permalink
while (have_posts()) : the_post();
?>
<a href="<?= get_permalink() ?>"><?= sanitize_title(get_the_title()) ?></a>
<?php
endwhile;
while(have_posts()):the_post();
?>
你能解释一下它是如何“链接不正确”的吗?请显示您当前拥有的输出与您需要的输出。没有发布地址。它只是将link语句作为文本输出。