在php变量中回显php_标题?
我如何回应:在php变量中回显php_标题?,php,wordpress,variables,title,Php,Wordpress,Variables,Title,我如何回应: <?php the_title(); ?> 在下面的变量中,在“q=”之后 类似这样的东西 <?php $feedURL = 'https://gdata.youtube.com/feeds/api/videos?q=' . get_the_title() . '&orderby=published&start-index=11&max-results=10&v=2'; ?> 您已经使用了php,因此无需再次
<?php the_title(); ?>
在下面的变量中,在“q=”之后
类似这样的东西
<?php
$feedURL = 'https://gdata.youtube.com/feeds/api/videos?q=' . get_the_title() . '&orderby=published&start-index=11&max-results=10&v=2';
?>
您已经使用了php,因此无需再次打开php标记。只需将变量连接到字符串上
<?php
$feedURL = 'https://gdata.youtube.com/feeds/api/videos?q=' . the_title() . '&orderby=published&start-index=11&max-results=10&v=2';
?>
编辑以供使用。而不是+来匹配PHP。试试这个
<?php
$title = the_title();
$feedURL = 'https://gdata.youtube.com/feeds/api/videos?q='.urlencode($title).'&orderby=published&start-index=11&max-results=10&v=2';
?>
您想在这里使用的是
获取标题()
您正在使用的函数(The_title()
)用于打印值(尽管您可以强制它只返回值,)
您的代码如下所示:
<?php
$feedURL = 'https://gdata.youtube.com/feeds/api/videos?q=' . get_the_title() . '&orderby=published&start-index=11&max-results=10&v=2';
?>
+
不是PHP中的串联运算符,您需要使用
。请查看更新的答案,它应该是“获取标题”,而不是WordPress+1中的“标题”,以解释原因并提供相关链接,而不是简单的“尝试此代码块”
”。好吧,为了完整性,值得注意的是连接问题,就像柯林的回答一样。
<?php
$feedURL = 'https://gdata.youtube.com/feeds/api/videos?q=' . get_the_title() . '&orderby=published&start-index=11&max-results=10&v=2';
?>