Placing a featured image into header

  1. How can I place featured images into the header, so each post has it's featured image within the main header?
  2. Also on category archive pages and the main news page, the featured images are being used in the traditional way, using the custom post image so is there a way around that too, where I can use the featured image for both posts and header.
  3. Maybe there is a way of having two custom thumbnail images and calling one up for the featured image and the other for the header?

Topic headers post-thumbnails images Wordpress

Category Web


Your question is confusing but I'll try.

Item 1

The $post variable is set before the template loads. It is preset to the first post in the Loop by the main query, so on single post/pages it matches the post/page that you are on and you can use it in the header to display your thumbnail.

Item 2

This is the most confusing of your questions. I am not really sure what you want. Again, the $post variable is set before the template loads. You could use that to display the thumbnail from the first post in the results in the header of the page. You would be using "the featured image for both posts and header" but there are potentially multiple thumbnails on a category archive so I am not sure that is what your really want.

Item 3

By default, there is not way to do this, but it pretty easy to have multiple featured images by way of custom meta fields.

See also: https://wordpress.stackexchange.com/a/109468/21376 A synopsis of that link: Trusting $post out of Loop context is a bit dicey unless you really understand WordPress template rendering internals. Using a function called get_queried_object can help get more expected behavior.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.