Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取自定义文章类型的标题作为其相关文章的链接?_Php_Html_Wordpress - Fatal编程技术网

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语句作为文本输出。