我在wordpress上的每个帖子上使用此代码自动添加内容内容:
function insertFootNote($content){
if(!is_feed() && !is_home()) {
$content.= "<div class='FollowMe'>";
$content.= "<h4>Enjoyed this article?</h4>";
$content.= "<p>Follow me .</p>";
$content.= "</div>";}
return $content;}
add_filter ('the_content', 'insertFootNote');
这很好但现在当我尝试插入一些图像时:
$content.= "<p> style="text-align: center;"><a href="http://www.especie.info/submit/"><img class="alignnone size-medium wp-image-744" src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-236x300.png" alt="imgpsh_fullsize" width="236" height="300" /></a> <a href="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2.png"><img class="alignnone size-medium wp-image-743" src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2-236x300.png" alt="imgpsh_fullsize-2" width="236" height="300" /></a></p>";
我收到此错误:解析错误:语法错误,意外“文本”(T_STRING)。
感谢您的帮助。
答案 0 :(得分:0)
这是因为你有双qoutes嵌套在双引号内,取消了自己。
您提交的以下代码已重构:
$content .= "
<p> style="text-align: center;">
<a href="http://www.especie.info/submit/">
<img class="alignnone size-medium wp-image-744"
src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-236x300.png" alt="imgpsh_fullsize" width="236" height="300" />
</a>
<a href="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2.png">
<img class="alignnone size-medium wp-image-743"
src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2-236x300.png" alt="imgpsh_fullsize-2" width="236" height="300" />
</a></p>";
应该成为:
$content = '
<p style="text-align: center;">
<a href="http://www.especie.info/submit/">
<img class="alignnone size-medium wp-image-744"
src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-236x300.png" alt="imgpsh_fullsize" width="236" height="300" />
</a>
<a href="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2.png">
<img class="alignnone size-medium wp-image-743"
src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2-236x300.png" alt="imgpsh_fullsize-2" width="236" height="300" />
</a>
</p> ';
旁注
您还没有将样式标记封装到第一个段落标记中。这已在重构版本中得到纠正。希望这有帮助!