我有一个wordpress网站,主页上显示了10篇最新的帖子。
我需要修改一些文本(因为重复的内容)在主页上,但不是在张贴页面。
我尝试修改索引中的以下行。php如下所示:
php the_content(Read more ...\');
php the_content(Read more ...\') . $content = str_replace(\'XXX\', \'YYY\');
但它不起作用,我找不到解决办法。有人能帮忙吗?非常感谢。
我有一个wordpress网站,主页上显示了10篇最新的帖子。
我需要修改一些文本(因为重复的内容)在主页上,但不是在张贴页面。
我尝试修改索引中的以下行。php如下所示:
php the_content(Read more ...\');
php the_content(Read more ...\') . $content = str_replace(\'XXX\', \'YYY\');
但它不起作用,我找不到解决办法。有人能帮忙吗?非常感谢。
the_content(Read more ...\')
直接回显内容,因此您无法使用str_replace
事后诸葛亮。
如果你想使用str_replace
你需要按照
$content = get_the_content( \'Read more ...\' );
$content = apply_filters( \'the_content\', $content );
$content = str_replace( \']]>\', \']]>\', $content );
$content = str_replace( \'xxx\', \'yyy\', $content );
echo $content;
用真正的ofc替代xxx和yyy。我发现这里的解决方案是工作代码:
$content = get_the_content( \'Read more ...\' );
$content = str_replace( \'XXX\', \'YYY\', $content );
echo apply_filters( \'the_content\', $content );
谢谢你。我想添加文本,但只显示在主页上。我使用了以下if脚本:<?php if( is_home() ) : ?> <p>Some text</p> <?php endif;?> 但问题是它出现在每个分页的页面上。例如,如果我查看http://www.example.com/page/2/ 它将显示该文本。我只希望它出现在第一页。有什么办法吗?