我希望能够替换wp标题中的文本,实际上有一个受欢迎文章的小部件。
我想要替换此小部件输出中的文本,所以我搜索了小部件功能并找到了以下代码:
foreach($popular as $post) :
setup_postdata($post);
?>
<li>
<a href="<?php the_permalink(); ?>">
<?php if ( $show_thumb3 == 1 ) : ?>
<?php the_post_thumbnail('widgetthumb',array('title' => '')); ?>
<?php endif; ?>
<?php the_title(); ?>
</a>
blah blah blah...
我尝试将这一行 <?php the_title(); ?>
改为:
<?php
$wptitle = the_title();
$wptitle = str_replace('textbefore', 'textafter', $wptitle);
echo $wptitle;
?>
但是在实际网站中没有任何作用,也没有任何影响!
我如何替换小部件输出标题中的文本?
如果有两个字符串需要替换,我该怎么办?
我应该使用类似这样的东西吗?:
<?php
$wptitle = the_title();
$wptitle = str_replace('textbefore', 'textafter', $wptitle) && str_replace('text2before', 'text2after', $wptitle);
echo $wptitle;
?>