【发布时间】:2016-05-26 17:55:26
【问题描述】:
我想替换 wp title 中的文本,
实际上,有一个热门帖子的小部件。
我想在这个小部件的输出中替换一个文本,所以我查看了小部件的功能,发现了这段代码:
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;
?>
【问题讨论】:
-
the_title() 函数用于显示帖子标题,并且该热门帖子插件还显示帖子部分的热门帖子,因此如果您想更改某些内容或想要添加内容,您可以附加到 the_title() 或您需要替换帖子标题
标签: php wordpress wordpress-theming