Img Src correct, but still not working in index.php

前提是你 提交于 2019-12-25 01:47:30

问题


I believe I've correctly sourced an image in html for a (super-basic) wordpress theme I am developing; however it still does not display.

This dialogue: Img Src on local computer shows the process so far (whereby I've been reassured the html is correct.)

body of index.php:

<?php
    $main_menu_column_top = array(
        'theme_location' => 'main-nav-column-top',
        'container' => 'nav',
        'container_class' => 'alignleft widecol',
        'container_id' => 'column-main-nav',
        'depth' => 1
    );
?>

<div class="leftcolumn">
    <div class="logo">
        <a href="http://www.petermaurin.com">
        <img src="images/pmsplogo.jpg" alt="Peter Maurin Screenprinters"/></a>
    </div><!--logo-->

    <div>
        <ul>
            <h1><?php wp_nav_menu ( $main_menu_column_top ); ?></h1>
        </ul>
    </div>
</div>

<div class="maincontent">

    <?php 
        if (have_posts()) :
            while (have_posts()) :
                the_post();
                the_title();
                the_content();
            endwhile;
        endif;
    ?>

    </div><!-- maincontent -->

functions.php:

<?php
register_nav_menus(
        array(
        'main-nav-column-top' => 'Main Nav, Top of Header',
        'sub-nav-column-bottom' => 'Sub Nav, Bottom of Header',
        'footer-nav' => 'Footer Menu'
    )
);

css:

* {
margin: 0;
padding: 0;
}

p {
font-family: Times New Roman;
}

body {
    font-size: 100%;
    font-family: sans-serif;
    background: url(images/tshirttexture.jpg) left repeat-y #0099ff;
}

.leftcolumn{
    width:365px;    
    float:left;
}

.maincontent{
    background-color:green;
    margin-left: 375px;
    max-width: 600px;
}

... if anyone can take a look and let me know why my image ('pmsplogo.jpg' on line 26 of index.php) is not displaying, I'd be very grateful!


回答1:


In the img element the src attribute should look like this

<?php bloginfo( 'template_url' );?>/images/pmsplogo.jpg

So basically the full image url will be:

<img src="<?php bloginfo( 'template_url' );?>/images/pmsplogo.jpg" alt="Peter Maurin Screenprinters"/>



回答2:


<img src="<?php echo 'dirname(__FILE__)'.'/images/pmsplogo.jpg'?>" />

Dont write with "http://www.yoursitename.com/" in PHP, they can't find source with it.



来源:https://stackoverflow.com/questions/15170419/img-src-correct-but-still-not-working-in-index-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!