-
AuthorPosts
-
September 1, 2014 at 3:43 am #96050
InnovataParticipantHello,
On the homepage of nieuw.teunvandekeuken.nl I’m using the shortcode recent posts without the featured image. Now only the titles and dates of the posts are published. But I also want to ad a short summary / excerpt under the titles with a read more link. Is this possible?
Thanks in advance.
September 1, 2014 at 3:51 am #96052
ChristianModeratorHey there,
Please see http://theme.co/x/member/forums/topic/add-excerpt-to-recent-posts-shortcode/#post-66964
Hope that helps. 🙂
September 1, 2014 at 4:18 am #96065
InnovataParticipantI followed the instruction in the link, but nothing happens. Still no excerpts under the post titles.
September 1, 2014 at 4:42 am #96077
Paul RModeratorHi,
Please note that switching from classic to visual composer may remove the enable_excerpt attribute since it is not a default option.
Would you mind trying the code below.
[recent_posts enable_excerpt="true" type="post" orientation="horizontal" no_image="true" category="Columns"]Thank you.
September 1, 2014 at 4:59 am #96080
InnovataParticipantUnfortenately. Not working.
September 1, 2014 at 5:08 am #96082
ChristopherModeratorHi there ,
You might want to try this plugin to add excerpt:
http://wordpress.org/plugins/advanced-excerpt/.Hope it helps.
September 1, 2014 at 6:31 am #96108
InnovataParticipantI installed the plugin, but only has effect on the blog index page. The recent posts on the homepage still don’t have an excerpt.
September 1, 2014 at 7:23 am #96135
ZeshanMemberHi Innovata!
Thank you for writing in!
Instead of using about codes, try adding the following code in your child theme’s functions.php file and see if it enables excerpt in your [recent_posts] shortcode:
// Recent Posts - Adding EXCERPT to recent_posts shortcode // ============================================================================= function x_shortcode_recent_posts2( $atts ) { extract( shortcode_atts( array( 'id' => '', 'class' => '', 'style' => '', 'type' => '', 'count' => '', 'category' => '', 'offset' => '', 'orientation' => '', 'no_image' => '', 'fade' => '' ), $atts ) ); $id = ( $id != '' ) ? 'id="' . esc_attr( $id ) . '"' : ''; $class = ( $class != '' ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf'; $style = ( $style != '' ) ? 'style="' . $style . '"' : ''; $type = ( $type == 'portfolio' ) ? 'x-portfolio' : 'post'; $count = ( $count != '' ) ? $count : 3; $category = ( $category != '' ) ? $category : ''; $category_type = ( $type == 'post' ) ? 'category_name' : 'portfolio-category'; $offset = ( $offset != '' ) ? $offset : 0; $orientation = ( $orientation != '' ) ? ' ' . $orientation : ' horizontal'; $no_image = ( $no_image == 'true' ) ? $no_image : ''; $fade = ( $fade == 'true' ) ? $fade : 'false'; $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} data-fade=\"{$fade}\">"; $q = new WP_Query( array( 'orderby' => 'date', 'post_type' => "{$type}", 'posts_per_page' => "{$count}", 'offset' => "{$offset}", "{$category_type}" => "{$category}" ) ); if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); if ( $no_image == 'true' ) { $image_output = ''; $image_output_class = 'no-image'; } else { $image_output = '<div class="x-recent-posts-img">' . get_the_post_thumbnail( get_the_ID(), 'entry-' . x_get_option( 'x_stack', 'integrity' ) . '-cropped', NULL ) . '</div>'; $image_output_class = 'with-image'; } $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ) . '">' . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">' . '<div class="entry-wrap">' . $image_output . '<div class="x-recent-posts-content">' . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>' . do_shortcode('[gap size="10px"]') . '<p>' . get_the_excerpt() . '</p>' . '<span class="x-recent-posts-date">' . get_the_date() . '</span>' . '</div>' . '</div>' . '</article>' . '</a>'; endwhile; endif; wp_reset_postdata(); $output .= '</div>'; return $output; } add_filter('init', function() { remove_shortcode( 'recent_posts' ); add_shortcode( 'recent_posts', 'x_shortcode_recent_posts2' ); });Hope this helps. 🙂
Thank you.
September 1, 2014 at 7:47 am #96154
InnovataParticipantWith or without using the plugin ‘Advanced excerpt’?
September 1, 2014 at 7:52 am #96158
InnovataParticipantI deactivated the plugin and added the code to the child’s function.php. No I can see the excerpts on the homepage of nieuw.teunvandekeuken.nl, but the styling is not ok. Could you have a look and explain what’s wrong?
September 1, 2014 at 8:25 am #96173
Paul RModeratorHi,
Would you mind taking a look if that is how you would like it to work.
http://nieuw.teunvandekeuken.nl/
The first code given was working except that you had pretty quotes.
I would like to suggest in copying shortcodes it is best to paste it first in notepad to
remove some formmating.Thank you.
September 1, 2014 at 8:45 am #96188
InnovataParticipantMuch better, but a few things:
– How do I get the ‘read more’ link under (with a linebreak) under the excerpts?
– How do I change the link color of the ‘read more’ link in these excerpts?
– Is the summary also working for this?September 1, 2014 at 9:31 am #96224
ChristopherModeratorHi,
Please add this code in function.php in child themefunction x_shortcode_recent_posts2( $atts ) { extract( shortcode_atts( array( 'id' => '', 'class' => '', 'style' => '', 'type' => '', 'count' => '', 'category' => '', 'offset' => '', 'orientation' => '', 'no_image' => '', 'fade' => '' ), $atts ) ); $id = ( $id != '' ) ? 'id="' . esc_attr( $id ) . '"' : ''; $class = ( $class != '' ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf'; $style = ( $style != '' ) ? 'style="' . $style . '"' : ''; $type = ( $type == 'portfolio' ) ? 'x-portfolio' : 'post'; $count = ( $count != '' ) ? $count : 3; $category = ( $category != '' ) ? $category : ''; $category_type = ( $type == 'post' ) ? 'category_name' : 'portfolio-category'; $offset = ( $offset != '' ) ? $offset : 0; $orientation = ( $orientation != '' ) ? ' ' . $orientation : ' horizontal'; $no_image = ( $no_image == 'true' ) ? $no_image : ''; $fade = ( $fade == 'true' ) ? $fade : 'false'; $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} data-fade=\"{$fade}\">"; $q = new WP_Query( array( 'orderby' => 'date', 'post_type' => "{$type}", 'posts_per_page' => "{$count}", 'offset' => "{$offset}", "{$category_type}" => "{$category}" ) ); if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); if ( $no_image == 'true' ) { $image_output = ''; $image_output_class = 'no-image'; } else { $image_output = '<div class="x-recent-posts-img">' . get_the_post_thumbnail( get_the_ID(), 'entry-' . x_get_option( 'x_stack', 'integrity' ) . '-cropped', NULL ) . '</div>'; $image_output_class = 'with-image'; } $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ) . '">' . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">' . '<div class="entry-wrap">' . $image_output . '<div class="x-recent-posts-content">' . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>' . do_shortcode('[gap size="10px"]') . '<p>' . get_the_excerpt() . '</p>' .'<span>'.'<a href="<?php the_permalink()?>">'.permalink.'</a>'.'</span>' . '<span class="x-recent-posts-date">' . get_the_date() . '</span>' . '</div>' . '</div>' . '</article>' . '</a>'; endwhile; endif; wp_reset_postdata(); $output .= '</div>'; return $output; } add_filter('init', function() { remove_shortcode( 'recent_posts' ); add_shortcode( 'recent_posts', 'x_shortcode_recent_posts2' ); });Hope it helps.
September 1, 2014 at 10:14 am #96240
InnovataParticipantOh no, now it’s displayed totally wrong again with this code!
September 1, 2014 at 11:40 am #96288
ZeshanMemberHi Innovata!
Thank you for writing in!
The above given code shouldn’t make any issue, would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:
– Link to your site
– WordPress Admin username / password
– FTP credentialsDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
Thanks!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-96050 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
