I am trying to display a blog page's featured image in a dynamic sidebar widget.
I've created a content template to display a post/page featured image (and title) as the page header image/title, using the widget shortcode:
[wpv-post-body view_template="Page Title Template"]
This works perfectly on all pages EXCEPT for the blog page.
The blog page is displaying the dynamic widget correctly, but it is using image and title for the FIRST BLOG POST instead.
Strangely, when I edit the dynamic widget, and choose the blog page in the live preview, it DOES display correctly - but not on the live blog page (see attached).
I'm pretty sure I need to add a conditional somewhere and manually set the image somehow:
The challenge here is that the blog page acts differently than regular pages and by the time the code in your content template executes, the loop for the blog/posts page is started.
This is how, I would overcome this:
1. I would register a new widget area "title-widget-area-blog", the same way the "title-widget-area" widget area is registered in the active child theme's "functions.php" file.
( screenshot: hidden link )
2. Next, in the child theme's "header.php" file, the code that loads this widget area can be changed, so that it loads existing "title-widget-area" on pages other than blog and new "title-widget-area-blog" on the blog page.
3. In the last step, I'll keep the content in the existing widget area "title-widget-area", as it is, but in the new "title-widget-area-blog", I'll add the content template shortcode with item="11" attribute, so that it loads the template's content from the page with ID "11" (Wholehearted Blog):
[wpv-post-body view_template="Page Title Template" item="11"]
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.