- This topic has 28 replies, 3 voices, and was last updated 4 years, 10 months ago by Hasan.
-
AuthorPosts
-
June 10, 2019 at 12:49 am #924521Hasan
I have a list created with WPShowPosts on this page: https://snapbangladesh.com/stories/
I am displaying the full post here, but need a way to shorten the text as an automatic excerpt.
If I use the “more” block, the image and text from the post appear on the archive pages, which is not expected: http://prntscr.com/nzucg2
If I use the manual excerpt on the post, the excerpt appears on the archive pages, which is not expected either: http://prntscr.com/nzudyo
Also, the full post is being shown on the show post list, because I’ve set it up to display the full post: http://prntscr.com/nzueuv
I can not set up the show post to display the excerpt because I need to display the main image from the post on this page along with an excerpt. Setting it up to show excerpt hides this image.
Please provide a solution!
June 10, 2019 at 3:21 am #924598DavidStaffCustomer SupportHi there,
the only real resolution to this is to add Featured Images to your posts instead of adding them as an Image Block in the content.
If you still wish to add them as an Image Block then you would need to also add them as the Featured Image and the Uncheck them from being displayed using the Customizer > Layout > Blog > Featured Image Options.
June 10, 2019 at 3:37 am #924613HasanThanks David!
Can’t use one image for both featured and post image. I need 2 different images for these because of the size and watermarking issue.
Any other idea?
June 10, 2019 at 4:25 am #924647DavidStaffCustomer SupportNot sure i full understand.
You can set a featured image that you can set to display only in the archives which will also display in WP Show Posts.Then the other image within the Content using your Image block.
What am i missing? π
June 10, 2019 at 4:31 am #924650HasanThe issue is, the featured images are small size images without watermark, which should be displayed only on the archive pages. But the image I need to show on the show post is a larger size image with watermark. If I display the featured image on the show post list, it will be stretched.
Hope you can come up with another great idea as usual! π
June 10, 2019 at 3:46 pm #925298DavidStaffCustomer SupportNot 100% sure on this but we could create a shortcode to get the first image in the post with this function ( add it to your child theme functions.php or code snippets plugin ):
function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+?src=[\'"]([^\'"]+)[\'"].*?>/i', $post->post_content, $matches); $first_img = $matches[1][0]; if(empty($first_img)) { $first_img = "/path/to/default.png"; } return '<img src="'.$first_img.'"/>'; } add_shortcode('first-image', 'catch_that_image');
Then we can hook the shortcode into WPSP.
Create a new Hook Element
Add the shorcode:[first-image]
Select Custom Hook and enter:
wpsp_before_content
Check the execute Shortcodes.
Set your display rules.As i said not 100% sure but lets see if we can the image in there and then worry about the styling.
June 11, 2019 at 5:42 am #925789HasanAwesome! It definitely is catching the first image except one: https://snapbangladesh.com/stories/
What’s next?
June 11, 2019 at 5:48 am #925794DavidStaffCustomer SupportOdd how it missed the first one – maybe try editing and republishing it.
So the code we used previously to make the post image the width of the container we can do the same to it:.wp-show-posts-entry-header + img { margin-left: -40px; width: calc(100% + 80px); max-width: calc(100% + 80px); }
June 11, 2019 at 6:02 am #925803HasanAwesome!! The image is full width now! (added the CSS on the style.css of the child theme)
Should I enable the excerpt view for the show post now instead of the full post?
June 11, 2019 at 6:05 am #925810DavidStaffCustomer SupportYeah then it should remove the second image.
June 11, 2019 at 6:18 am #925820HasanPerfect!
How to insert a link of “License this image” after the image?
Need to insert the following HTML exactly:
<a href="#" class="license-caption-link">License this image</a>
June 11, 2019 at 6:36 am #925845DavidStaffCustomer SupportYou could include it within the shortcode within this rule:
return '<img src="'.$first_img.'"/>';
like so:
return '<img src="'.$first_img.'"/><a href="#" class="license-caption-link">License this image</a>';
June 11, 2019 at 6:59 am #926002HasanPerfect! π
Is it possible to insert the same link after the image on the single posts too? I am doing it manually now by assigning the block as a reusable block as you suggested on a previous thread. But the problem is, when I convert the reusable block to a regular block on a new post, the caption goes away. I then need to insert the link manually, which is not convenient.
Could it be done?
June 11, 2019 at 7:17 am #926026DavidStaffCustomer SupportIf your Image will always be the first block the you could add content filter to strip in the tag before the first paragraph like so:
add_filter( 'the_content', 'db_insert_before_first_paragraph' ); function db_insert_before_first_paragraph( $content ) { if ( is_single() ) { $my_div = '<a href="#" class="license-caption-link">License this image</a>'; $first_para_pos = strpos( $content, '<p' ); $new_content = substr_replace( $content, $my_div, $first_para_pos, 0 ); return $new_content; } return $content; }
June 11, 2019 at 7:44 am #926058HasanWorked perfectly! π
Now the last part to fix on this is, I’ve set automatic excerpt for a long post, which is now being shown on the archive page: https://snapbangladesh.com/
How can I stop the excerpt being generated on the archive page?
-
AuthorPosts
- You must be logged in to reply to this topic.