如何通过本地链接在wordpress中使用图像?

时间:2018-01-12 20:24:10

标签: php html wordpress

在此代码中,我想使用保存在笔记本电脑中的内部图像。使用的代码被复制,并使用外部链接。问题是改变路径后图像没有出现,所以告诉我是否遗漏了什么。提前致谢

    <div class="row home-team">
<div class="col-md-3 col-sm-6 dream-team-item">
<div class="row dream-team-detail">
<div class="img-thumbnail">
<p><img class="img-responsive home_team_thumb wp-post-image" src="C:/xampp/htdocs/wordpress/wp-content/themes/dream/images/image.jpg" alt="" width="1140" height="760"></p>
<div class="overlay"></div>
</div>
<h3 class="member-name"><a href="#"> Name</a></h3>
<p>( Age)</p>
</div>
</div>

以下是原始代码:

 <div class="col-md-3 col-sm-6 dream-team-item">
    <div class="row enigma-team-detail">
    <div class="img-thumbnail">
    <p><img class="img-responsive home_team_thumb wp-post-image" src="http://demo.com/dream-premium/wp-content/uploads/sites/23/2016/10/team1-1140x760.jpg" alt="" width="1140" height="760"></p>
    <div class="overlay"></div>
    </div>
    <h3 class="member-name"><a href="#"> Thomash</a></h3>
    <p>( CEO)</p>
    </div>
    </div>

1 个答案:

答案 0 :(得分:2)

我看到路径不同,在这种情况下,我建议为图像使用相同的文件夹(主题或上传)。

如果要在两个环境(web和localhost)中使用“themes”文件夹,可以这样使用:

<?php
  #this line below returns http://yourwebsite/wp-content/themes
  $themes_path = get_theme_root_uri();  
?>
<p><img class="img-responsive home_team_thumb wp-post-image" src="<?=$themes_path;?>/dream/images/image.jpg" alt="" width="1140" height="760"></p>

现在,如果您想继续使用“uploads”文件夹,可以执行以下操作:

<?php
  $upload_dir   = wp_upload_dir();
?>
<p><img class="img-responsive home_team_thumb wp-post-image" src="<?=$upload_dir['baseurl'];?>/sites/23/2016/10/team1-1140x760.jpg" alt="" width="1140" height="760"></p>

使用 $ upload_dir ['basedir'] ,您会获得完整的网址“http://yourwebsite/wp-content/uploads/http://localhost/wp-content/uploads/”;