admin管理员组

文章数量:1278793

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 3 years ago.

Improve this question

First time making a wordpress theme. I can't seem to get my header to display on certain pages (archive.php). It displays perfectly fine on my front page, etc. Just not in the archive or individual posts. My code is below...

archive.php

<?php get_header();?>
<div class="container">

<h1><?php single_cat_title();?></h1>

<?php if (have_posts()) : while(have_posts()) : the_post();?>


<div class="card mb-4">
    <div class="card-body">
    <?php if (has_post_thumbnail()):?>

<img src="<?php the_post_thumbnail_url('smallest');?>" class="img-fluid">

<?php endif;?>
    <h3><?php the_title();?></h3>
    <?php the_excerpt();?>
    <a href="<?php the_permalink();?>" class="btn btn-success">Read more</a>
    </div>
    </div>
<?php endwhile; endif;?>

</div>
<?php get_footer();?>

front-page.php

<?php get_header();?>
<div class="container">

<h1><?php the_title();?></h1>

<?php if (have_posts()) : while(have_posts()) : the_post();?>

    <?php the_content();?>

<?php endwhile; endif;?>

</div>
<?php get_footer();?>

header.php

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
   
    <head>
            <?php wp_head(); ?>
            <div class="logo">
    <img class="logo" src="img/pmflogolandscapedemo_crop.png" width="100%" alt="">
</div>
    </head>

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



<header>

<div class="container">
    <?php wp_nav_menu (

        array(

            'theme_location' => 'top-menu',
            'menu_class' => 'navigation'

        )

    );
    ?>
</div>

</header>

Is there a different file in the theme that might be causing this? I can't seem to spot any issues between this page and other ones like my front-page.php, where the header displays fine.

Thanks in advance for any assistance, I'm really struggling with the basics here.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 3 years ago.

Improve this question

First time making a wordpress theme. I can't seem to get my header to display on certain pages (archive.php). It displays perfectly fine on my front page, etc. Just not in the archive or individual posts. My code is below...

archive.php

<?php get_header();?>
<div class="container">

<h1><?php single_cat_title();?></h1>

<?php if (have_posts()) : while(have_posts()) : the_post();?>


<div class="card mb-4">
    <div class="card-body">
    <?php if (has_post_thumbnail()):?>

<img src="<?php the_post_thumbnail_url('smallest');?>" class="img-fluid">

<?php endif;?>
    <h3><?php the_title();?></h3>
    <?php the_excerpt();?>
    <a href="<?php the_permalink();?>" class="btn btn-success">Read more</a>
    </div>
    </div>
<?php endwhile; endif;?>

</div>
<?php get_footer();?>

front-page.php

<?php get_header();?>
<div class="container">

<h1><?php the_title();?></h1>

<?php if (have_posts()) : while(have_posts()) : the_post();?>

    <?php the_content();?>

<?php endwhile; endif;?>

</div>
<?php get_footer();?>

header.php

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
   
    <head>
            <?php wp_head(); ?>
            <div class="logo">
    <img class="logo" src="img/pmflogolandscapedemo_crop.png" width="100%" alt="">
</div>
    </head>

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



<header>

<div class="container">
    <?php wp_nav_menu (

        array(

            'theme_location' => 'top-menu',
            'menu_class' => 'navigation'

        )

    );
    ?>
</div>

</header>

Is there a different file in the theme that might be causing this? I can't seem to spot any issues between this page and other ones like my front-page.php, where the header displays fine.

Thanks in advance for any assistance, I'm really struggling with the basics here.

Share Improve this question asked Oct 9, 2021 at 23:52 perezperez 31 bronze badge 1
  • 1 you have div and img tags inside your head tag, that's not valid HTML. It also uses a hardcoded relative URL so the location it looks in is different on every page which is probably not what you wanted. I don't think any of your issues are WordPress but rather fundamental HTML problems – Tom J Nowell Commented Oct 10, 2021 at 0:56
Add a comment  | 

1 Answer 1

Reset to default 0

I guess the problem relies on the header.php file. head tag doesn't support a div or img. However, browsers like Chrome autocorrect the issue by moving the div from head to body.

The header logo is working on the front-page because you set a relative path for the logo. So when you are on the homepage, the logo URL becomes yoursite.tld/img/pmflogolandscapedemo_crop.png. Maybe the logo exists there. But when you visit an archive page, the logo URL becomes yoursite.tld/{archive-url}/img/pmflogolandscapedemo_crop.png where the image doesn't exist.

On the header.php file, you may try this.

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
    <head>
            <?php wp_head(); ?>
    </head>
<body <?php body_class(); ?>>
<header>
<div class="logo">
    <img class="logo" src="<?php echo get_template_directory_uri(); ?>/img/pmflogolandscapedemo_crop.png" width="100%" alt="">
</div>
<div class="container">
    <?php
    wp_nav_menu(
        array(

            'theme_location' => 'top-menu',
            'menu_class'     => 'navigation',

        )
    );
    ?>
</div>

</header>

get_template_directory_uri() will return the URI to current theme's template directory. So if you put the image within the img directory of the active theme, the image will load on all the pages.

本文标签: phpHeader is not displaying on certain pages of wordpress theme