Php 在wordpress上添加自动上下文帖子
我会在我的wordpress上的每篇帖子上自动添加内容,并使用此代码:Php 在wordpress上添加自动上下文帖子,php,wordpress,Php,Wordpress,我会在我的wordpress上的每篇帖子上自动添加内容,并使用此代码: function insertFootNote($content){ if(!is_feed() && !is_home()) { $content.= "<div class='FollowMe'>";
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){
如果(!is_feed()&&!is_home()){
$content.=”;
$content.=“喜欢这篇文章吗?”;
$content.=“跟我来。”;
$content.='';}
返回$content;}
添加_过滤器(“_内容”,“插入脚注”);
这很好,但现在当我尝试插入一些图像时:
$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.=”style=“文本对齐:居中;“>”;
我得到这个错误:解析错误:语法错误,意外的“文本”(T_字符串)
感谢您的帮助。这是因为您在双引号中嵌套了双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.=”
style=“文本对齐:居中;">
”;
应成为:
$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='1!'
';
旁注
您也没有将样式标记封装到第一段标记中。这已在重构版本中得到纠正。希望这有帮助