【问题标题】:Images wont show in wordpress图片不会在wordpress中显示
【发布时间】:2013-12-08 11:07:44
【问题描述】:

所以,

我的图片位于 wp-content/themes/mytheme/images

最初,当我从 html/css 转换我的网站时,路径如下所示:

<img src="images/myimage.png" alt="some text" />

这不起作用,我现在尝试了两种不同的解决方案:

<img src='<?php get_template_directory_uri(); ?>/images/myimage.png'>

<img src="<?php bloginfo(); ?>images/myimage.png">

我错过了什么吗?我是 wordpress 和 php 的新手,希望能得到一些帮助。谢谢!

【问题讨论】:

    标签: php wordpress image visibility


    【解决方案1】:

    试试

    get_stylesheet_directory(). '/images';
    

    /images/myimage.png"> 这将返回当前选定主题中的图像目录路径,即使它是子主题。

    Function Reference/get stylesheet directory

    【讨论】:

    • 如果我理解正确的话,我应该把“模板”这个词改成“目录”吗?可以请你写完整路径吗?
    【解决方案2】:

    你几乎拥有它。你离开了echo

    http://codex.wordpress.org/Function_Reference/get_template_directory_uri

    输出 URI

    <?php echo get_template_directory_uri(); ?>
    

    完整的结果是:

    <img src='<?php echo get_template_directory_uri(); ?>/images/myimage.png'>
    

    如果您还没有深入了解 WP,我建议您使用 Drupal。 :)

    【讨论】:

    • 您如何在不知道 OP 需求的情况下推荐一个而不是另一个?您是说在任何情况下 Drupal 是更好的选择吗?
    • 成功了!非常感谢 =) 另外,感谢 Drupal 提示,也许需要研究一下。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-06-29
    • 2017-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多