duancan1900 2011-06-26 22:02
浏览 115
已采纳

Wordpress中的字符串连接

In my Wordpress site, I am trying to retrieve the most recent 10 posts and store them in a string. After that I will write this content into a text file. Below is the code I am using.

<?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);?>

The problem is, when I execute this page, the permalink and title are returning in this page and empty ''....'' tags are coming in text file. If I am not using the string, the href tags are returning correctly in the same file.

  • 写回答

2条回答 默认 最新

  • dtx9931 2011-06-26 22:05
    关注

    the_permalink() and the_title() does not return anything they are to print values.

    You have to use their get_ version. Those are get_permalink() and get_the_title()

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部