- This topic has 32 replies, 8 voices, and was last updated 2 years, 2 months ago by
Fernando.
-
AuthorPosts
-
September 7, 2020 at 1:56 am #1433610
Yolanda
Yes, thank you, that was stupid of me… ๐
September 7, 2020 at 5:52 am #1433829Leo
StaffCustomer SupportNo problem ๐
June 30, 2022 at 5:52 pm #2269763guyhanchet
I’ve been looking for this for some time and finally took the plunge on adding a snippet of code using the recommended plugin and a bit of CSS as suggested here. It all works as I hoped.
July 1, 2022 at 2:41 am #2270081David
StaffCustomer SupportGlad to hear you found that of use!
October 9, 2022 at 9:15 pm #2368284Erik
This has mostly worked for me, with one problem: The caption is also showing up underneath thumbnail images for the posts in the sidebar. Is there a way to prevent this, so that it only shows up on the main featured image at the top of the post?
October 10, 2022 at 12:15 am #2368378Fernando Customer Support
Hi Erik,
Try replacing this:
if( $html == '' ) {
with:
if( $html == '' || ! is_single() || ! is_main_query() ) {
November 27, 2022 at 5:06 pm #2437992Henry
Removing caption in single page sidebar didn’t work for me after replacing with
if( $html == ” || ! is_single() || ! is_main_query() ) {
November 27, 2022 at 5:48 pm #2438024Henry
Also, the code here, https://gist.github.com/diggeddy/5f7c3a4584a8beb51febc9c4f33d6c5c kind of floats the featured image to the left. I don’t want text around the featured image.
UPDATE: RESOLVED! Forgot I added CSS.
November 27, 2022 at 6:43 pm #2438070Fernando Customer Support
I see. Glad you resolved the issue!
November 28, 2022 at 12:02 am #2438302Henry
THIS PROBLEM has not been resolved
November 28, 2022 at 12:13 am #2438314Fernando Customer Support
I see. Can you make sure that the quotation marks you used in the code are not slanted? To make sure, can you add the code you added here? Make sure to Highlight the code, and click on “CODE” here in the forum text box so it’s added as a code.
November 28, 2022 at 12:26 am #2438333Henry
To recall, Everything works fine except for the single-post sidebar. See https://scholarsly.com/uniqlo-student-discount/
add_filter( 'post_thumbnail_html', 'custom_add_post_thumbnail_caption',10,5 ); function custom_add_post_thumbnail_caption($html, $post_id, $post_thumbnail_id, $size, $attr) { if( $html == '' || ! is_single() || ! is_main_query() ) { return $html; } else { $out = ''; $thumbnail_image = get_posts(array('p' => $post_thumbnail_id, 'post_type' => 'attachment')); if ($thumbnail_image && isset($thumbnail_image[0])) { $image = wp_get_attachment_image_src($post_thumbnail_id, $size); if($thumbnail_image[0]->post_excerpt) $out .= '<div class="wp-caption thumb-caption">'; $out .= $html; if($thumbnail_image[0]->post_excerpt) $out .= '<p class="wp-caption-text thumb-caption-text">'.$thumbnail_image[0]->post_excerpt.'</p></div>'; } return $out; } }
November 28, 2022 at 12:46 am #2438353Henry
Also you’ll notice the the sidebar “Latest Post” push to the right and not left. How do I resolve that?
November 28, 2022 at 1:01 am #2438380Fernando Customer Support
I see. I can see the captions from my end. See: https://share.getcloudapp.com/geuOlqqR
Also, with regards to your second inquiry, can you clarify a bit more about how you would like it to look?
Alternatively, you can also use a GB Query Loop Block to show the Latest Posts. GB Image Blocks has the option to add captions as well.
Example: https://share.getcloudapp.com/KounDwl9
Also see: https://share.getcloudapp.com/4gu4bJOlReference: https://docs.generateblocks.com/article/query-loop-overview/
November 28, 2022 at 1:38 am #2438423Henry
I actually don’t want the caption shown.
Well, I’ve updated the side using GB Query Loop Block (Check the link above). How do I achieve something similar to https://share.getcloudapp.com/P8uNpyro.
And another with numbering & without featured image.
-
AuthorPosts
- You must be logged in to reply to this topic.