Skip Navigation

[Resolved] Using dynamic sidebar widget for blog page

This support ticket is created 2 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Waqar 2 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2171181
ss2.jpg
Screen Shot 2021-09-16 at 11.57.53 AM.png

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:

if get_option('page_for_posts')

...but I'm not sure where or how to do this.

#2171697

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot and suggest the best way to achieve this, I'll need to see how this dynamic sidebar widget is set up.

Can you please share temporary admin login details, along with the link to the blog page in question?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#2176261

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing these details.

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.

Current code:


<?php if (is_active_sidebar( 'title-widget-area' ) ) : ?>
 <?php if (!is_archive()) : ?>
	<div id="page-title-sidebar" class="title-widget-area">
		<?php dynamic_sidebar( 'title-widget-area' ); ?>
	</div>
 <?php endif; ?>
<?php endif; ?>

Updated code:


<?php if (is_active_sidebar( 'title-widget-area' ) ) : ?>
 <?php if ( (!is_archive()) && (!is_home()) ) : ?>
	<div id="page-title-sidebar" class="title-widget-area">
		<?php dynamic_sidebar( 'title-widget-area' ); ?>
	</div>
 <?php endif; ?>
<?php endif; ?>

<?php if (is_active_sidebar( 'title-widget-area-blog' ) ) : ?>
 <?php if ( is_home() ) : ?>
	<div id="page-title-sidebar" class="title-widget-area title-widget-area-blog">
		<?php dynamic_sidebar( 'title-widget-area-blog' ); ?>
	</div>
 <?php endif; ?>
<?php endif; ?>

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.