gpt4 book ai didi

php - Wordpress 中的字符串连接

转载 作者:行者123 更新时间:2023-12-04 00:47:22 25 4
gpt4 key购买 nike

在我的 Wordpress 站点中,我试图检索最近的 10 篇文章并将它们存储在一个字符串中。之后我会将这些内容写入一个文本文件。下面是我正在使用的代码。

<?php $str  = ''; ?>
<?php
require_once('../wp-blog-header.php');
query_posts('&showposts=10&order=DESC&caller_get_posts=1');
while (have_posts()) : the_post(); ?>
<?php $str .= '<a href="' . the_permalink() . '">' .the_title() . '</a>'; ?>
<?php endwhile; ?>
<?php $fp = fopen("latestposts.txt", "w");
fwrite($fp, $str);
fclose($fp);?>

问题是,当我执行此页面时,永久链接和标题返回此页面,空的“....”标 checkout 现在文本文件中。如果我没有使用该字符串,则 href 标签会在同一文件中正确返回。

最佳答案

the_permalink()the_title()不返回任何打印值。

你必须使用他们的 get_版本。这些是 get_permalink()get_the_title()

<?php $str .= '<a href="' . get_permalink() . '">' .get_the_title() . '</a>'; ?>

关于php - Wordpress 中的字符串连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6489142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com