- This topic has 23 replies, 4 voices, and was last updated 3 years, 3 months ago by
Ying.
-
AuthorPosts
-
December 8, 2022 at 6:25 am #2454508
Carl
If I create a new post as type “link” it would be nice, that I get to the link url via pressing the read more button or clicking on the image.
How can I do that?Thank you!
December 8, 2022 at 7:34 am #2454592David
StaffCustomer SupportHi there,
can i see the archive page with the Link format posts on it ?
December 12, 2022 at 7:31 am #2459025Carl
https://www.denkanstösse-limburgerhof.info/1670829360831/
The first two items are link posts, the third item is a normal post.
I have installed this snipped:
https://docs.generatepress.com/article/activating-read-custom-excerpt/So now I get on the link by klicking on the post header if I have inserted an URL in the excerpt field. But then is no read more button displayed.
In the third post, there is a read more button displayed.
It doesn‘t looks nice if sometimes we have and sometimes we havent a read more button.
It would be nice, if everytime a read more button would be displayed and I can get to the url by clicking on the read more button and on the image.
(Now I have a css display none on the read more button so that it is more uniformly).
Thank you!December 12, 2022 at 10:45 am #2459453David
StaffCustomer SupportFor the Featured Image you can try this PHP Snippet:
add_filter( 'generate_featured_image_output', function( $output ) { $content = get_the_content(); $has_url = get_url_in_content( $content ); $url = ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); return sprintf( '<div class="post-image"> %3$s <a href="%1$s"> %2$s </a> </div>', esc_url( $url ), get_the_post_thumbnail( get_the_ID(), apply_filters( 'generate_page_header_default_size', 'full' ), $attrs ), apply_filters( 'generate_inside_featured_image_output', '' ) ); });Are you still wanting the Read More ?
December 12, 2022 at 1:59 pm #2459622Carl
Hi David,
thank you very much!!!
My customer still wanting the Read More 😉
Kind regards
WolfgangDecember 12, 2022 at 7:58 pm #2459815Fernando Customer Support
Hi Carl,
You can create a Block Element with a Dynamic GB Button Block for the Read More button. Just set the link source to Single Post. Example: https://share.getcloudapp.com/p9uLPWll
Then, set the Hook to
after_entry_contentfor instance.Set it to Display on your Blog page.
December 17, 2022 at 2:46 am #2464907Carl
Hi Fernando,
thank you! But now the link goes to the “single post”, but it should go to the link inserted into the excerpt field (or a custom field, …), if there is inserted a link. If not, it should go to the single post, like the link on the image and on the title.
Kind Regards
WolfgangDecember 17, 2022 at 8:52 am #2465249David
StaffCustomer SupportYou can change the Link Source to
Post Metaand in the field it provides add your custom field name.December 19, 2022 at 1:49 am #2466640Carl
OK, thank you David! It do not display the field in the pulldown-menu, but I have typed in the name and now it runs.
I would now like that this element is only used when displaying posts with the type “link” or rather only when a link is entered in the custom field.
How would you do that?My apologies for asking such beginner questions, but I think once I get the hang of it, I might be able to better utilize Generate Press’s potential.
December 19, 2022 at 4:20 am #2466768David
StaffCustomer SupportIs the Content Source also set to display the Custom Field ( Post Meta ) ?
If it is then when there is no custom field value to return it will remove the block.December 19, 2022 at 6:15 am #2466902Carl
Yes, that’s what I thought too, but the normal post still doesn’t display a link on the “Read more” button. The button only works if I enter the URL of the post in the link field.
December 19, 2022 at 6:52 am #2466934David
StaffCustomer SupportOk, i had to have a re-read of the topic.
Just to be clear what is the preference for the Read More:
a. Is it to use a the first URL in the content like we did for the Featured Image?
b. is it to use a dynamic value from a Custom Field ?Let me know as both options will require some PHP and ill write that up.
December 19, 2022 at 7:09 am #2466960Carl
The best solution would be: If the url for the featured image, headline and read more would be taken from the “link” field created via ACF. And if no URL is entered, the contribution URL should be output for all 3 places.
It would be ideal if I could then adjust the settings for the number of words in the excerpt.Thank you a lot!
December 20, 2022 at 2:47 am #2467928David
StaffCustomer SupportOk, so try this:
// Replace featured image link with custom field value add_filter( 'generate_featured_image_output', function( $output ) { $has_url = get_post_meta(get_the_ID(), 'your_custom_field', true); $url = ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); return sprintf( '<div class="post-image"> %3$s <a href="%1$s"> %2$s </a> </div>', esc_url( $url ), get_the_post_thumbnail( get_the_ID(), apply_filters( 'generate_page_header_default_size', 'full' ), $attrs ), apply_filters( 'generate_inside_featured_image_output', '' ) ); }); // Replace exceprt more link with custom field value add_filter('generate_excerpt_more_output', function(){ $has_url = get_post_meta(get_the_ID(), 'your_custom_field', true); $url = ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); return sprintf( ' ... <a title="%1$s" class="read-more" href="%2$s" aria-label="%4$s">%3$s</a>', the_title_attribute( 'echo=0' ), esc_url( $url ), __( 'Read more', 'generatepress' ), sprintf( /* translators: Aria-label describing the read more button */ _x( 'More on %s', 'more on post title', 'generatepress' ), the_title_attribute( 'echo=0' ) ) ); }); // Replace title link with custom field value add_filter('generate_get_the_title_parameters', function($params){ if ( ! is_singular() && ! 'link' === get_post_format() ) { $has_url = get_post_meta(get_the_ID(), 'your_custom_field', true); $url = ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); $params = array( 'before' => sprintf( '<h2 class="entry-title"%2$s><a href="%1$s" rel="bookmark">', esc_url( $url ), 'microdata' === generate_get_schema_type() ? ' itemprop="headline"' : '' ), 'after' => '</a></h2>', ); } return $params; });All 3 of the filter get the field from post meta on this line:
$has_url = get_post_meta(get_the_ID(), 'your_custom_field', true);You need to update the custom field value there or you can replace the get_post_meta with the ACF equivalent get_field also.
December 20, 2022 at 3:31 am #2467964Carl
Thank you so much David!!! I´ll try it tomorrow and give you feedback.
Kind regards
Wolfgang -
AuthorPosts
- You must be logged in to reply to this topic.