Wordpress在post中的替换字符串


Wordpress substitute string in post

你好,我有从另一个页面到我的wordpress站点的rss提要。它自动从rss提要创建帖子。但在rss提要是链接到图像,我需要改变它到另一个链接。我写这个脚本

<?php 
$link="http://www.example.com/thumbs/329/t2_f2ba40a1092b2039a1cf71d2a2b76e91.jpg";
$start = strpos($link, 'thumbs');
$end = strpos($link, 't2_'  )+3;
$length = $end - $start;
$vypis = substr($link, $start, $length);
$new = str_replace($vypis, "i/", $link);
echo $new;
?>

它工作得很好,但我不知道我应该把这个脚本在wordpress模板。以及如何从帖子自动获得链接并获得$link,请有任何想法吗?

这里是插件http://wordpress.org/plugins/feedwordpress/rss提要。它会自动创建帖子,它可以在任何模板中工作。for循环的代码是这个<?php the_content('Celý článek &raquo;'); ?>

post

示例
<a href="http://www.example.com/spray-on-clothes-34751.html"><img src="http://www.example.com/thumbs/329/t2_f2ba40a1092b2039a1cf71d2a2b76e91.jpg"/><br />Click to see the full pic.</a><br/><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/example?a=JFKec5JGE9M:rVB15gLhJKs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/example?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/example?a=JFKec5JGE9M:rVB15gLhJKs:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/example?i=JFKec5JGE9M:rVB15gLhJKs:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/example?a=JFKec5JGE9M:rVB15gLhJKs:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/example?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/example?a=JFKec5JGE9M:rVB15gLhJKs:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/example?i=JFKec5JGE9M:rVB15gLhJKs:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/example/~4/JFKec5JGE9M" height="1" width="1"/>   

是的,那么您应该能够用以下代码替换the_content('Celý článek &raquo;')。它将提取页面内容(不输出到浏览器),使用代码替换URL,然后输出到浏览器。诀窍在于每次都要识别URL。我需要看到完整的帖子源,以便能够使用正则表达式或其他方法来识别要替换的URL。

$content = get_the_content(); // get post content
$content = apply_filters('the_content', $content); // apply formatting
$content = str_replace(']]>', ']]&gt;', $content); // apply formatting
// This specifically will need modification, to identify the URL... 
// I would need to see example post content to find out how
$link="http://www.example.com/thumbs/329/t2_f2ba40a1092b2039a1cf71d2a2b76e91.jpg";
$start = strpos($link, 'thumbs');
$end = strpos($link, 't2_'  )+3;
$length = $end - $start;
$vypis = substr($link, $start, $length);
$new = str_replace($vypis, "i/", $link);
$content = str_replace( $link, $new, $content ); // Replace URL in content
echo $content; // Output to browser