-
AuthorPosts
-
November 26, 2022 at 3:00 pm #1373946
Hi,
I have a blog section.
I then have articles published including css such as bold text or H1, H2, etc.
Finaly, I logically have a blog list of articles page, listing articles and displaying few lines extractHow can keep the original article’s CSS in the blog list extract? For eg bold charachters or H1, H2, etc.
Thanks for your help
Have a nice day
JMDPNovember 26, 2022 at 10:11 pm #1373990Hey Ad-Min747,
Try adding this code to the end of your child theme functions.php file in Appearance ▸ Editor:if ( ! function_exists( 'wpse_custom_wp_trim_excerpt' ) ) : function wpse_custom_wp_trim_excerpt( $wpse_excerpt ) { $raw_excerpt = $wpse_excerpt; if ( '' == $wpse_excerpt ) { $wpse_excerpt = get_the_content( '' ); $wpse_excerpt = strip_shortcodes( $wpse_excerpt ); $wpse_excerpt = apply_filters( 'the_content', $wpse_excerpt ); $wpse_excerpt = str_replace( ']]>', ']]>', $wpse_excerpt ); //Set the excerpt word count and only break after sentence is complete. $excerpt_word_count = 75; $excerpt_length = apply_filters( 'excerpt_length', $excerpt_word_count ); $tokens = array(); $excerptOutput = ''; $count = 0; // Divide the string into tokens; HTML tags, or words, followed by any whitespace preg_match_all( '/(<[^>]+>|[^<>\s]+)\s*/u', $wpse_excerpt, $tokens ); foreach ( $tokens[0] as $token ) { if ( $count >= $excerpt_length && preg_match( '/[\,\;\?\.\!]\s*$/uS', $token ) ) { // Limit reached, continue until , ; ? . or ! occur at the end $excerptOutput .= trim( $token ); break; } // Add words to complete sentence $count++; // Append what's left of the token $excerptOutput .= $token; } $wpse_excerpt = trim( force_balance_tags( $excerptOutput ) ); $excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . ' » ' . sprintf( __( 'Read more about: %s »', 'wpse' ), get_the_title() ) . '</a>'; $excerpt_more = apply_filters( 'excerpt_more', ' ' . $excerpt_end ); $wpse_excerpt .= $excerpt_more; /* Add read more in new paragraph */ return $wpse_excerpt; } return apply_filters( 'wpse_custom_wp_trim_excerpt', $wpse_excerpt, $raw_excerpt ); } endif; remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); add_filter( 'get_the_excerpt', 'wpse_custom_wp_trim_excerpt' );
Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.
Best regards,
MikeDecember 4, 2022 at 3:56 pm #1375011Hi Mike,
thanks for your answer (1st I modify the functions.php.It says that there’s an error:
Vos modifications de code PHP ont été annulées en raison d’une erreur sur la ligne 30 du fichier wp-content/themes/enfold-child/functions.php. Veuillez la corriger et réessayer d’enregistrer.
(PHP code modifications have been cancelled due to a mistake line 30 of wp-content/themes/enfold-child/functions.php.Please modify and retry)syntax error, unexpected ”, $wpse_excerpt, $tokens );’ (T_CONSTANT_ENCAPSED_STRING)
I have retried to copy paste but it didn’t work.
Any idea?Best regards
JMVPS: In case of wp upgrade or plugin or else, isn’t that a risk to modify the functions.php file?
December 4, 2022 at 10:28 pm #1375037Hi,
Did you copy the code from the forum? Copying from an email would cause this error.
Your child theme functions.php will not be changed in an update.
I tested this on my test site before I posted it and I didn’t receive an error, please include an admin login in the Private Content area so we can check.Best regards,
MikeDecember 5, 2022 at 4:53 pm #1375126Hi,
yes, from the forum. Just tried again, and got the same message: “erreur sur la ligne 30 du fichier wp-content/themes/enfold-child/functions.php”.Do I have to remove the two /* sentences?
BR
JMDecember 5, 2022 at 8:59 pm #1375150Hi,
Thanks for the login, I didn’t see any errors when I added it, please check.Best regards,
MikeDecember 6, 2022 at 10:06 pm #1375287Hi Rikard,
thanks. I’m not very used to such a modif and think I was copying the code before the */ instead of after. (I thought I had to copy the code “in between”) So, thanks again.Nevertheless, in the bloglist of article, in the excerpt, color for bold or H3 is great but:
– First article in the list and others, In the excerpt there shouldn’t be “» Read more about: FERWAY® : NOUVELLE IDENTITÉ DE MARQUE DU FRET FERROVIAIRE »”.
There should only have “lire la suite” at the bottom right which is perfect.– In several articles, the blue sentence such as “La “raison d’être d’entreprise”, nouvelle plateforme stratégique” in the 2nd article, or “Stratégie de marque : un nom de marque identitaire et accessible à tous” etc.are in the right color (thanks) but alined.with the paragraph below.
Would you be able to modify, this or tell me how to?
Many thanks
Best regards
JMDecember 7, 2022 at 7:48 pm #1375420Hi,
Thanks for the feedback, I believe that I have modified it as you wished, please clear your browser cache and check.Best regards,
MikeDecember 10, 2022 at 1:43 pm #1375765Hi Mark,
yes you’ve done it ! :-)
Many thanks
Have a nice day!
JMDecember 10, 2022 at 2:00 pm #1375767Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘Blog list, keep article extract CSS in the Blog List view’ is closed to new replies.