1

我在回显包含多个值/变量的字符串时遇到问题。

这是PHP:

            echo '" alt="'.the_title ().'"height="500px" width="940px"data-caption="#'.$post->ID.'" />';
            echo '
            <span class=" orbit-caption" id="'.$post->ID.'"><a href="'.$permalink.'"><h3>'.the_title ().'</h3></a><br /><p>'.wp_trim_excerpt().'</p></span>
            ';

这导致了这个(五个之一):

<img src= "http://msc-media.co.uk/wp-content/uploads/2012/07/wpid-IMAG00421.jpgDay Thirteen &#8211; Undissapointing French castles" alt=""height="500px" width="940px"data-caption="#178" />Day Thirteen &#8211; Undissapointing French castles

<span class=" orbit-caption" id="178"><a href="http://msc-media.co.uk/?p=178"><h3></h3></a><br /><p>We finally decided to take advantage our free entry to Peyrepetouse, the pictures say it all really! Was super windy near the top, so much so that the falconry show in the castle lost a few birds, which we watched fight the wind to try to get back to their masters for over 30 minutes, [...]</p></span>

问题在于 .the_title()。没有出现在 alt="" 标记中,但在与 img src 合并之前。第二个问题是,对于 span orbit-caption,the_title() 没有输出,因为它应该出现在标签之间。

让我知道我哪里出错了?- 或者我应该把这个字符串分成更多的 echo-s 吗?

4

1 回答 1

4

尝试使用get_the_title();

因为

the_title()做类似的事情,并且不返回字符串。

function the_title() { echo get_the_title(); }

所以它在您的回声呼叫之前调用。

于 2012-08-05T15:26:34.557 回答