使用图像作为现有WordPress中的链接PHP
问题描述:
我试图将当前PHP生成的文本链接改为图像链接。使用图像作为现有WordPress中的链接PHP
这是我的索引页面上的导航,显示以前的帖子或下一篇文章,如果有一些可用,所以它不是一个静态图像链接。
这里是原代码:
<div class="next"><?php previous_posts_link(__('‹ Newer Posts', 'imbalance2')); ?></div>
<div class="previous"><?php next_posts_link(__('Older Posts ›', 'imbalance2')); ?></div>
我想改变的箭头(&#8249 + &#8250)与文成我做只是PNG图像。
这是我的一个尝试。
<div class="next"><?php previous_posts_link(__(<?php echo "<img src="wp-content/images/srnewerposts.png" /></a>"; ?>)); ?></div>
<div class="previous"><?php next_posts_link(__(<?php echo "<img src="wp-content/images/srolderposts.png" /></a>"; ?>)); ?></div>
这会产生一个错误:
Parse error: syntax error, unexpected '<', expecting ')'
我最初试图只是把文件路径没有PHP的echo标签,但没想到的是/我的路径的开始。
我做了很多搜索,但无法找到有帮助的东西。
答
试试这个:
$srnewerposts = content_url().'/images/srnewerposts.png';
$srolderposts = content_url().'/images/srolderposts.png';
<div class="next"><?php previous_posts_link("<img src='".$srnewerposts."' />" ); ?></div>
<div class="previous"><?php next_posts_link("<img src='".$srolderposts."' />"); ?></div>
这是伟大的,谢谢!为了让它起作用,我在变量的前两行添加了一个php标签。 – user3221637
“试试这个”和代码只有答案不是很好的答案,因为他们没有解释问题是什么以及如何解决它。 –
@JohnConde我的回答需要更多关于问题和承诺的信息。感谢您的评论。我完全理解。你的建议将在我的下一个答案中执行:)。 – vrajesh