$image_src
doesn’t exist yet when the “Header_Upper_Left” div appears. So, you’d need to place the code for deriving whichever image you want to have used before you actually use $image_src
.
There are a couple of ways to do this. One way that a lot of themes do it –
like ones that have a top “Featured Post” or “Posts” format, is to start the query, get only the most recent post (and its data, attachments, whtaever), then rewind the query if you’re using it as main loop and displaying the same post again.
The alternative would be just to separate the special div from the main query, and use a separate query or a wrapper like get_posts() or wp_get_recent_posts(), to get the post ID, and then use the post ID to get the attachment ID.
Related Posts:
- Woocommerce get category image full size
- Display the featured image from the last post
- Add Image Size for one Media Category Only
- Extract image url associated to a category
- Retrieve Image from Media Library by it’s category
- Show category images on single product page and product overview page
- Link Attachment Image to Category
- Change thumbnail image depending product category
- category image taxonomy
- get_post_meta not working on category.php
- Random Featured Image Based on Category
- Category images are not displaying in WordPress
- Need to echo category id in multi-dimensional array
- Category view with contents of [gallery]s shown
- How to add image for all posts associated to specified category?
- How to display WooCommerce category image in my category page banner as a background?
- How to make product image inherit from category image
- How to display categories image in loop homepage WordPress
- Change background image page header overlay for each category
- Image Upload Custom Form Field for Category and Custom Taxonomy
- Icon images across multiple categories
- Media Categories as Classes on WordPress Gallery Shortcode
- How to relocate images
- In a shared site, how to get products in a category from one site to another?
- Display one post on category.php: Wrong featured image
- Category page with gallery for each post
- Image menu showing categories in page
- Get all first images of posts in same category
- Add category image before post title on homepage
- how do i set an image for a category in admin panel
- How to link images of one WP site to another WP site?
- How to create a photo gallery that can be filtered by the image categories
- Images as Categories
- How to create an automatic MultiColoumn MegaMenu with Categories WordPress
- Is There a Difference Between Taxonomies and Categories?
- List all subcategories from category
- How To Find Out WordPress Category Table in MYSQL?
- Add custom field to Category
- Get Category ID inside Category template
- Only one category per post
- WordPress Multisite – global categories
- Get the children of the parent category
- Get posts from sites in Multisite?
- WP REST API: filter by category 1 AND category 2
- How To Get Parent Category Slug of Current Post
- Display All Products by Category with WooCommerce
- What is the difference between a “tag” and a “category”?
- Is there an easy way to make a meta box have the tabs like the Categories meta box has?
- How to check if I’m on the last page of posts?
- Display posts from the same category using next/previous post link
- How would I get a taxonomy/category list inside a Gutenberg block?
- Can I set a default featured image for a category?
- Check if a post is in any child category of a parent category
- How to export and import taxonomies (category, tag and/or custom taxonomy) and their terms
- Force category choice before creating new post?
- Gutenberg editor add a custom category as wrapper for custom blocks
- WooCommerce: List All Categories
- How to get category and archive title?
- Get category ID from category slug (not working)
- How do I remove “Uncategorized” from posts with more than 1 category?
- Get rid of WordPress category, tag and author archives?
- Individual rss feed entry length for categories?
- How can I create a category landing page followed by pages of posts?
- Remove parent category from permalink? Basically only have the child category?
- Custom permalink structure leads to be 404 on pagination
- Retrieve Product category ‘NAME’ by product category ID – WooCommerce?
- Posts URL structure like site.com/category/the-post-title
- Can’t custom taxonomies have same terms (slugs) as categories?
- How to get permalinks with category base working with sub-categories
- How to remove the term “category” from category pagination?
- Using wp_category_checklist in a widget
- WP 3.9 TinyMCE no longer loads on category description editor
- On the category page, get the category object
- Get only the top level categories using get_categories() without foreach loop
- Get all categories and posts in those categories
- How to add featured image for category (without a plugin)?
- How to create a custom sort for WordPress categories
- How to display non-hierarchical taxonomy as terms with checkboxes?
- Category archive by year with permalink support /category/YYYY
- Best Way to Redirect Category to Page and Hide Category
- get_terms vs. get_categories: does it matter?
- What is a good robots.txt?
- Allow users to create their own feed from selected categories?
- Hook when category is added to post
- get_categories for custom post type with a specific custom taxonomy attached
- Add a URL prefix to permalinks of one category of posts only
- How do you add categories to custom post types in WordPress?
- Create a category list page
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- exclude category from get_posts?
- How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling
- How can I hide a category from Contributors in the edit/add new post screen?
- Order get_terms() By Custom Field
- WordPress Multiple Category Search
- Should category.php and The Loop be used if the query needs to be customizable?
- How do the ‘tag’ and ‘category’ (default) taxonomies do ‘save_post’ action?
- How to Change the Categories Order in the Admin Dashboard?
- Control term order on a per-post basis
- How to remove categories filter from wordpress admin?
- get all tags from category