在主页(wordpress / html / css)以外的其他页面中显示图片时出现问题 [英] Trouble showing images in other pages than Home (wordpress/html/css)

查看:250
本文介绍了在主页(wordpress / html / css)以外的其他页面中显示图片时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个小型网站正在为客户做,我已经使用了一个html / css网站,并通过使用空白主题将其转移到wordpress。到目前为止,看看energyshop.se,如果你想,并且在开始页面显示前两个图像,但不是其他选项卡 - 为什么?我将这些图像添加到header.php中,以便它可以在所有标签上找到它们...?

// header.php

 < body<?php body_class(); ?>> 

< div id =container>










 < div id =headeronclick =location.href ='http: //www.energyshop.se/; style =cursor:pointer;> 
< h1>< a href =<?php echo get_option('home');?> /><?php bloginfo('name'); ?>< / A>< / H1>
< div class =description><?php bloginfo('description'); ?>< / DIV>
< / div>
< div id =main_menu>
<?php wp_nav_menu(); ?>
< / div>


解决方案

这是因为您使用的是相对路径。当创建一个WordPress主题并且你想从你的主题加载资源时,你应该使用绝对路径。有两个模板标签可以方便您: get_bloginfo() bloginfo()。第一个返回值,第二个返回值(您通过传递给函数的第一个参数请求的值)。

因此,为了显示图像,你应该有:

 < img src =<?php bloginfo('stylesheet_directory');?> / images / icon_en_global.pngalt =English.png> 

这总是会导致这种情况(对于您的网站):

 < img src =http://energyshop.se/wp-content/themes/blank/images/icon_en_global.pngalt =English.png > 

因此,只需替换所有 wp-content / themes / blank <?php bloginfo('stylesheet_directory'); ?>


Hi I have a small website im doing for a customer and I have used a html/css-site and transferred it to wordpress by using blank theme. So far so good, have a look at energyshop.se if u want and in startpage the top two images are shown, but not udner the rest of the tabs - why? I add the images in the header.php so it should find them on all tabs...?

//header.php

<body <?php body_class(); ?>>

<div id="container">

    <div id="header" onclick="location.href='http://www.energyshop.se/';" style="cursor: pointer;">
        <h1><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></h1>
        <div class="description"><?php bloginfo('description'); ?></div>
    </div>
<div id="main_menu">
<?php wp_nav_menu(); ?>
</div>

解决方案

This is because you're using relative paths. When creating a WordPress theme and you want to load resources from your theme, you should use absolute paths. There are two template tags that make this easy for you: get_bloginfo() and bloginfo(). The first one returns the value, and the second one echoes the value(that you request via the first argument passed to the function).

So in order to display an image, you should have:

<img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon_en_global.png" alt="English.png">

This will always result in this(for your site):

<img src="http://energyshop.se/wp-content/themes/blank/images/icon_en_global.png" alt="English.png">

So simply replace all wp-content/themes/blank with <?php bloginfo('stylesheet_directory'); ?>.

这篇关于在主页(wordpress / html / css)以外的其他页面中显示图片时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆