我正在尝试在DIV上添加base64 / SVG图像,具体取决于我在Wordpress上发布的帖子类型。如果它是一个视频,它会显示一个播放图标,如果它是一个音频,它会显示一个耳机图标。
以下是代码:
if ( in_category ( 'video' )) {
$mediaPlay = "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDkuMTI2IDEwOS4xMjYiPjxwYXRoIGQ9Ik05OC45IDQ3LjY2M0wxOC4xOTggMS4wNjhjLTIuNDY3LTEuNDI0LTUuNTAyLTEuNDI0LTcuOTcyIDBDNy43NjIgMi40OSA2LjI0MyA1LjEyNCA2LjI0MyA3Ljk3djkzLjE5YzAgMi44NDcgMS41MjIgNS40NzggMy45ODIgNi45IDEuMjM2LjcxMiAyLjYxIDEuMDY2IDMuOTg2IDEuMDY2IDEuMzc3IDAgMi43NTQtLjM1NCAzLjk4Ni0xLjA2N0w5OC45IDYxLjQ2MmMyLjQ2NS0xLjQyMiAzLjk4My00LjA1NCAzLjk4My02LjkuMDA1LTIuODQ2LTEuNTE2LTUuNDc3LTMuOTgtNi45MDJ6IiBmaWxsPSIjRkZGIi8+PC9zdmc+";
} elseif ( in_category ( 'audio' )) {
$mediaPlay = "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMzAgMzMwIj48cGF0aCBkPSJNMzAwIDE3NS44di0yMS41NmMwLTc0LjQ0LTYwLjU2LTEzNS0xMzUtMTM1UzMwIDc5LjggMzAgMTU0LjI0djIxLjU2Yy0xOC4yMDQgMTMuNjk2LTMwIDM1LjQ3NS0zMCA1OS45NTggMCA0MS4zNTUgMzMuNjQ0IDc1IDc1IDc1IDguMjg0IDAgMTUtNi43MTYgMTUtMTV2LTEyMGMwLTguMjg0LTYuNzE2LTE1LTE1LTE1LTUuMTM2IDAtMTAuMTUyLjUyLTE1IDEuNTF2LTguMDI1YzAtNTcuODk3IDQ3LjEwMy0xMDUgMTA1LTEwNXMxMDUgNDcuMTAzIDEwNSAxMDV2OC4wMjVjLTQuODQ4LS45OS05Ljg2NC0xLjUxLTE1LTEuNTEtOC4yODQgMC0xNSA2LjcxNi0xNSAxNXYxMjBjMCA4LjI4NCA2LjcxNiAxNSAxNSAxNSA0MS4zNTUgMCA3NS0zMy42NDUgNzUtNzUgMC0yNC40ODQtMTEuNzk2LTQ2LjI2Mi0zMC01OS45NnoiIGZpbGw9IiNGRkYiLz48L3N2Zz4=";
} else {
$mediaPlay = "";
}
应该使图像显示的HTML是:
<img src="data:image/svg+xml;base64,<?php echo $mediaPlay; ?>">
问题在于这种调节方法是行不通的。它的方式,它显示了一个破碎的图像,只是因为它没有将base64代码添加到应该的位置。
如果我只是尝试这个,没有条件,比如:
$mediaPlay = "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMzAgMzMwIj48cGF0aCBkPSJNMzAwIDE3NS44di0yMS41NmMwLTc0LjQ0LTYwLjU2LTEzNS0xMzUtMTM1UzMwIDc5LjggMzAgMTU0LjI0djIxLjU2Yy0xOC4yMDQgMTMuNjk2LTMwIDM1LjQ3NS0zMCA1OS45NTggMCA0MS4zNTUgMzMuNjQ0IDc1IDc1IDc1IDguMjg0IDAgMTUtNi43MTYgMTUtMTV2LTEyMGMwLTguMjg0LTYuNzE2LTE1LTE1LTE1LTUuMTM2IDAtMTAuMTUyLjUyLTE1IDEuNTF2LTguMDI1YzAtNTcuODk3IDQ3LjEwMy0xMDUgMTA1LTEwNXMxMDUgNDcuMTAzIDEwNSAxMDV2OC4wMjVjLTQuODQ4LS45OS05Ljg2NC0xLjUxLTE1LTEuNTEtOC4yODQgMC0xNSA2LjcxNi0xNSAxNXYxMjBjMCA4LjI4NCA2LjcxNiAxNSAxNSAxNSA0MS4zNTUgMCA3NS0zMy42NDUgNzUtNzUgMC0yNC40ODQtMTEuNzk2LTQ2LjI2Mi0zMC01OS45NnoiIGZpbGw9IiNGRkYiLz48L3N2Zz4=";
<img src="data:image/svg+xml;base64,<?php echo $mediaPlay; ?>">
它有效,我不知道为什么。
我该如何解决这个问题?
谢谢。 :)