-
AuthorPosts
-
August 27, 2015 at 11:55 am #371408
Hi there,
There is currently no option to enable excerpt in Cornerstone. Though, we’ve forwarded this feature request to our developers for future consideration.
In the meantime, if you want to enable excerpts by default in recent posts, you can use the following code instead of the provided one in your child theme’s functions.php file:
// ============================================================================= // Custom Excerpt Length - Call: echo excerpt($length); // ============================================================================= function excerpt($limit) { $excerpt = explode(' ', get_the_excerpt(), $limit); if (count($excerpt)>=$limit) { array_pop($excerpt); $excerpt = implode(" ",$excerpt).'.'; } else { $excerpt = implode(" ",$excerpt); } // $excerpt = preg_replace('<code>\[[^\]]*\]</code>','',$excerpt); return $excerpt; } // ============================================================================= // Add Excerpt to Recent Posts -> [x_recent_posts] // ============================================================================= function x_shortcode_recent_posts_excerpt( $atts ) { extract( shortcode_atts( array( 'id' => '', 'class' => '', 'style' => '', 'type' => 'post', 'count' => '', 'category' => '', 'offset' => '', 'orientation' => '', 'no_image' => '', 'fade' => '' ), $atts, 'x_recent_posts' ) ); $allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post' ) ); $type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post'; $id = ( $id != '' ) ? 'id="' . esc_attr( $id ) . '"' : ''; $class = ( $class != '' ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf'; $style = ( $style != '' ) ? 'style="' . $style . '"' : ''; $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'; $js_params = array( 'fade' => ( $fade == 'true' ) ); $data = cs_generate_data_attributes( 'recent_posts', $js_params ); $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >"; $q = new WP_Query( array( 'orderby' => 'date', 'post_type' => "{$type}", 'posts_per_page' => "{$count}", 'offset' => "{$offset}", "{$category_type}" => "{$category}", 'ignore_sticky_posts' => true ) ); if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); if ( $no_image == 'true' ) { $image_output = ''; $image_output_class = 'no-image'; } else { $image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'entry-cropped' ); $bg_image = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : ''; $image_output = '<div class="x-recent-posts-img"' . $bg_image . '></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"', csl18n() ), 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>' . '<span class="x-recent-posts-date">' . get_the_date() . '</span>' . do_shortcode('[x_gap size="10px"]') . '<span class="x-recent-posts-excerpt">' . strip_tags(excerpt(25)) . '</span>' . '</div>' . '</div>' . '</article>' . '</a>'; endwhile; endif; wp_reset_postdata(); $output .= '</div>'; return $output; } add_action('wp_head', 'update_x_recent_posts_to_v2'); function update_x_recent_posts_to_v2() { remove_shortcode( 'x_recent_posts' ); add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_excerpt' ); }
Thanks!
August 27, 2015 at 12:00 pm #371410Great thank you, what exactly do I do with that? Just stick it into the function.php thing?
August 27, 2015 at 12:03 pm #371412Just to clarify, this is my site
If I stick in that code at the bottom of my functions.php
Will it enable post excerpts under the recent posts sections
eg the latest bits in prin
and
eg
the latest blog post parts of the site?
Thanks!!
August 27, 2015 at 6:48 pm #371687Hi There,
Yes, it should. Paste the code on your child themeโs functions.php file. Just below the:
// Additional Functions // =============================================================================
Hope it helps, Cheers!
August 28, 2015 at 4:48 am #372116Hi guys
I stuck that in there as per the instructions but no dice.
Am I missing another setting?
All I’m looking for is a few lines of excerpt below the various sections on the front.
I love the new website, its stunning so thank you for all your help and a great theme.
August 28, 2015 at 5:52 am #372150Hi Rabbler,
Upon checking, I’m not seeing any child theme activated in your site. Please activate it under Settings > Themes. Once it is activated, you should be able to see the appropriate changes.
Thank you for your kind words! ๐ And let us know how it goes.
Cheers!
August 28, 2015 at 6:41 am #372178What?! Sorry, I thought that was active all along. I just activated the child theme and it appears to have broken the site.
What do I do now?? http://rabble.ie
๐
August 28, 2015 at 9:41 am #372269Fixed this by deleting child theme via FTP. Ill work on the excerpts later. Thanks again.
August 28, 2015 at 10:07 am #372284Child theme activated again and all working fine, that code was stuck into functions.php
Still can’t see any excerpts on the front page though?
August 28, 2015 at 11:44 am #372331Hi Rabbler,
I’ve tested the code in my local setup and it is working just fine. To assist you better with this, kindly open a separate thread and provide us with your WordPress admin and FTP login credentials in a private reply (you can create a new reply to your new thread for the logins) so that we can take a closer look to the issue.
Thanks!
August 28, 2015 at 1:10 pm #372383Hi I’m trying to achieve the same thing…. I’m using ethos stack child theme and would like to have excerpt on my recent posts under the image title and the post’s date… But when I paste the code in the function.php I receive this error:
Fatal error: Call to undefined function x_generate_data_attributes() in /home/psylist/public_html/deewan.ca/wp-content/themes/x-child/functions.php on line 97What do I do wrong?
Thanks!
August 28, 2015 at 10:35 pm #372683Hello There,
Thanks for updating this thread. The error occurred because you are using an older version of the recent post shortcode. Please replace this line:
$data = x_generate_data_attributes( 'recent_posts', $js_params );
with this line instead:
$data = cs_generate_data_attributes( 'recent_posts', $js_params );
This should remove the error in your child theme’s functions.php file.
Please let us know how it goes.
September 4, 2015 at 5:17 am #378747Is it possible to have the exceprt use “<br>” and “<p>” somehow?
September 4, 2015 at 5:37 am #378770Hi there,
This is not possible as excerpts remove any tags, script or shortcodes from the text and display it as a normal text. You can find more information regarding excerpts in WordPress codex: https://codex.wordpress.org/Excerpt.
Though, it could be possible with custom development, but this would be outside the scope of support we can offer. You may wish to consult a developer to assist you with this. X is quite extensible with child themes, so there are plenty of possibilities.
Thanks for understanding. Take care!
September 4, 2015 at 1:45 pm #379121Hi!
I tried adding the code a few posts above the my functions.php in my child theme, but no excerpts shows up. I’m using the Renew stack.
-
AuthorPosts