PHP 串联和 Wordpress
PHP Concatenation and Wordpress
我正在使用带有高级自定义字段 (ACF) 的 wordpress 并尝试将 the_title();
与 PHP 变量 $address_city
连接在一起,然后将它们放在一些 HTML。 (我有一个 'citystates' 的分层分类法,我在其中输入了城市、州和邮政编码)。
我的完整代码如下:
$terms = get_the_terms( $post->ID, 'citystates' );
$address_city = (' '. $terms[1]->name . ', '. $terms[2]->name . ' '. $
terms[0]->name);
$address_beg = the_title();
$address_full = ($address_city ." ". $address_beg);
echo "<p>" .$address_full. "</p>";`
如果我的标题是“1234 56th Street”并且城市州分类法 ($address_city
) 是 "New York, New York 11001" 那么它应该显示为“1234 56th Street New York, New York 11001”包装在 "p" 标签中。
我的问题是只有 "New York, New York 11001" 被包裹在 "p" 标签中,而不是完整地址。
我得到的 HTML 输出是:
"
1234 56th Street "
<p> New York, New York 11001
</p>
我知道这很简单,但我需要帮助来解决这个问题,并且已经花了很多时间在谷歌上搜索答案。先谢谢你了。
答案在问题的评论中,非常简单。
使用 get_the_title()
代替 the_title()
我正在使用带有高级自定义字段 (ACF) 的 wordpress 并尝试将 the_title();
与 PHP 变量 $address_city
连接在一起,然后将它们放在一些 HTML。 (我有一个 'citystates' 的分层分类法,我在其中输入了城市、州和邮政编码)。
我的完整代码如下:
$terms = get_the_terms( $post->ID, 'citystates' );
$address_city = (' '. $terms[1]->name . ', '. $terms[2]->name . ' '. $
terms[0]->name);
$address_beg = the_title();
$address_full = ($address_city ." ". $address_beg);
echo "<p>" .$address_full. "</p>";`
如果我的标题是“1234 56th Street”并且城市州分类法 ($address_city
) 是 "New York, New York 11001" 那么它应该显示为“1234 56th Street New York, New York 11001”包装在 "p" 标签中。
我的问题是只有 "New York, New York 11001" 被包裹在 "p" 标签中,而不是完整地址。 我得到的 HTML 输出是:
"
1234 56th Street "
<p> New York, New York 11001
</p>
我知道这很简单,但我需要帮助来解决这个问题,并且已经花了很多时间在谷歌上搜索答案。先谢谢你了。
答案在问题的评论中,非常简单。
使用 get_the_title()
代替 the_title()