dop2144 2016-03-03 16:26
浏览 364

WordPress:需要更改RSS Feed中的帖子永久链接URL

For some reason, I need a slight change in the URLs that go out with the RSS feed of my WP-powered blog. Currently, the permalinks look like this:

http://www.thesite.com/blogs/post_title

This is the URL that's going into my RSS feed (a custom feed I built) as well. However, I need the URL to go with blog instead of blogs:

http://www.thesite.com/blog/post_title

To that end, this is what I tried using the str_replace() function with WP's the_permalink_rss() in my custom feed PHP (rss-burrofeed.php) code and here's the snippet illustrating this hack in context:

   <item>
        <title><?php the_title_rss(); ?></title>
        <link><?php str_replace('/blogs/','/blog/',the_permalink()); ?></link>
        <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
         <dc:creator><?php the_author(); ?></dc:creator>
         <guid isPermaLink="false"><?php the_guid(); ?></guid>
         <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
         <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
         <?php rss_enclosure(); ?>
         <?php do_action('rss2_item'); ?>
</item>

But this is not working. The links are still appearing with blogs and not blog. Am I doing something wrong? Why isn't str_replace() working?

  • 写回答

1条回答 默认 最新

  • duanjuduo4573 2016-03-03 21:32
    关注

    Is posible than the function the_permalink() is generate other info, because I try and found me

        $phrase  = "http://www.thesite.com/blogs/post_title";
        $newphrase = str_replace('/blogs/','/blog/',$phrase);
    
        print_R($phrase);
        print_R('<br>');
        print_R($newphrase);
    

    and print:

    http://www.thesite.com/blogs/post_title
    http://www.thesite.com/blog/post_title

    the parameter is string, I think than the function dont give data equal!

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题