是否有可能在PHP内使用PHP?

时间:2014-02-01 08:23:46

标签: php wordpress

我正在学习php,现在我遇到了一个问题,我无法找到答案。

我用

<?php include 'text1.php'; echo get_text($var2); ?>

阅读本文

<?php $var2 = "This is some text" ?>

将文字放在wordpress页面上。

我的问题是: 如何将wordpress标题放在wordpress页面上的文本This is some text之后? IE浏览器。 This is some text - Go To New York? (其中Go To New York是博客标题)

获取帖子标题的php是 <?php the_title(); ?>

我尝试了这个,但当然不会起作用;-)

<?php $var2 = "This is some text - <?php the_title(); ?>" ?>

是否有其他方法可以在文本后输出wordpress标题?

谢谢!

1 个答案:

答案 0 :(得分:2)

PHP中的PHP,你可以,但你需要删除php标签,在你的情况下,使用concatenation运算符(点)将the_title()附加到$ var2。

如果我理解你的问题,

<?php include 'text1.php'; echo get_text($var2)." - ".the_title(); ?>