• Resolved chewbears

    (@chewbears)


    I found the following from a post 6 years ago.

    <?php
    if(is_single() & !is_home()) {
      $myfield = 'custom_field_name'; // Change this to the name of the custom field you use..
      $postimage = get_post_meta($post->ID, $myfield, true);
    ?>
      <style type="text/css">
      <!--
        .yourheaderclass {
            border:none;
            color:black;
          <?php
          if($postimage) { // If the field has a value.. set background image using value...
          ?>
            background-image: url('some/path/to/image/<?php echo $postimage; ?>.jpg');
          <?php
          } elseif(!$postimage) { // If no value
          ?>
            background-image: none;
          <?php
          }
          ?>
        }
      -->
      </style>
    <?php
    }
    ?>

    I do not have ‘custom_field_name’ and am unsure if the php is still usable. Can anyone confirm if this still works or have a solution for 4.4.2.

    Regards,

    Matt

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter chewbears

    (@chewbears)

    Figured I would get this type of response due to a poor title name maybe. Anyways if anyone sees this here is a neat trick to do it. This is the half a** way, but hey it works.

    Make 1 new header call it header-blank.php
    Copy all the goodies form your stock header you want.
    Then all you have to do is add this little bit of code.

    <div class="yourheaderclass"><img src="http://www.YOURSITE.com/blog/wp-content/uploads/2016/02/<?php the_ID(); ?>.jpg" alt=""></div>

    NOW name the photos, the jpgs in your media the same as your post id. Don’t know your post ID. <p>Post Number: <?php the_ID(); ?></p> Post that in your header and it will tell you. Yes its not amazing, but it works.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘HOw to create a unquie Header on every post’ is closed to new replies.