Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果要在Wordpress中测试home_Php_Wordpress - Fatal编程技术网

Php 如果要在Wordpress中测试home

Php 如果要在Wordpress中测试home,php,wordpress,Php,Wordpress,我有一个在我的自定义可湿性粉剂主题标题图像横幅,在网页上,而不是帖子。我需要这个横幅在主页上是不同的。我已经创建了一个首页模板,并具有以下内容: <?php if (is_front_page()){ ?> <div class="banner"> <?php if ( get_header_image() ) : ?> <a href="<?php echo esc_

我有一个在我的自定义可湿性粉剂主题标题图像横幅,在网页上,而不是帖子。我需要这个横幅在主页上是不同的。我已经创建了一个首页模板,并具有以下内容:

    <?php if (is_front_page()){ ?>
        <div class="banner">
            <?php if ( get_header_image() ) : ?>
                <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
                    <img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
                </a>
        </div><!-- #banner -->

    <?php else { ?>
        <div class="banner">
            <?php if ( get_header_image() ) : ?>
                <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
                    <img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
                </a>
            <?php endif; // End header image check. ?>
        </div><!-- #banner -->

我在这里两次使用同一个图像只是为了测试,但是得到一堆错误。我的php不是很好。有人能帮忙吗

这里没什么好说的,只需将您的代码替换为:

<?php if (is_front_page()){ ?>
    <div class="banner">
        <?php if ( get_header_image() ) : ?>
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
                <img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
            </a>
        <?php endif; ?>
    </div><!-- #banner -->
<?php } else { ?>
    <div class="banner">
        <?php if ( get_header_image() ) : ?>
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
                <img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
            </a>
        <?php endif; // End header image check. ?>
    </div><!-- #banner -->
<?php } ?>
给大家一点启发:

你忘了一个结尾}{ 你错过了一个尾声;之前
如果你没有告诉我们什么不起作用/你遇到了什么错误,那么你就不会有太多的错误。如果这是你的代码的精确副本,你至少应该删除最后3行,其中一行是空的,但仍然要删除。这是WP中错误的屏幕截图。在其他行之前,你错过了一个右大括号。你必须添加一个closi在else部分的else和end之前加上大括号,同时缺少endif