簡體   English   中英

WordPress:需要更改RSS feed中的帖子永久鏈接URL

[英]WordPress: Need to change post permalink URL in RSS feed

出於某種原因,我需要對由WP驅動的博客的RSS feed附帶的URL進行一些更改。 當前,永久鏈接如下所示:

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

這也是我的RSS供稿源(我構建的自定義供稿源)中的URL。 但是,我需要URL隨博客一起而不是博客

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

為此,這是我在自定義feed PHP(rss-burrofeed.php)代碼中將str_replace()函數與WP的the_permalink_rss()結合使用的嘗試,以下是在上下文中說明這種黑客攻擊的代碼段:

   <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>

但這不起作用。 鏈接仍與博客一起出現,而不是博客 難道我做錯了什么? 為什么str_replace()不起作用?

比函數the_permalink()可以生成其他信息更合適,因為我嘗試找到了我

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

    print_R($phrase);
    print_R('<br>');
    print_R($newphrase);

並打印:

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

參數是字符串,我認為比函數不給數據相等!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM