Tagged: x
-
AuthorPosts
-
July 21, 2016 at 5:00 pm #1097749
ironmalParticipantI’ve read every thread I could find starting with one that’s 5 years old on this subject. For new site malmilligan.com. I got a new excerpt to work but it’s word based so when the “recent posts element” is set to horizontal, the vertical length is frequently uneven on the bottom although each post has identically sized featured images. So I saw a thread where someone got a fix to make the excerpt length character based and have it not truncate at the end in the middle of a word. But it was an old solution. Can you tell me what I need to do that? I’ll add the child theme functions.php for word based excerpts as an attachment.
One additional note, I had unlimited developer lics for Revolution / Revolution 2 / StudioPress / and Elegant. I think both Brian Gardner and Nick Roach made modules like your Cornerstone Recent Posts back in 2008 for their WP Themes with selectors for character based excerpts and a toggle for a hyperlinked inline “read more”. I apologize in advance if I’m wrong about the exact year but it was way back and it saved all the users a lot of hair pulling. It would save you money in reduced support questions for sure if you built the excerpt length controls into your “element”. I saw some solutions here in the forum that offered using a text overflow display none but I might avoid that to eliminate any possibility that Google thought there was hidden text of any kind.
Thanks – Regards, Mal
July 21, 2016 at 5:01 pm #1097750
ironmalParticipant<?php
// =============================================================================
// FUNCTIONS.PHP
// —————————————————————————–
// Overwrite or add your own custom functions to X in this file.
// =============================================================================// =============================================================================
// TABLE OF CONTENTS
// —————————————————————————–
// 01. Enqueue Parent Stylesheet
// 02. Additional Functions
// =============================================================================// Enqueue Parent Stylesheet
// =============================================================================add_filter( ‘x_enqueue_parent_stylesheet’, ‘__return_true’ );
// Additional Functions
// =============================================================================// Additional Functions
// =============================================================================function x_shortcode_recent_posts_v2code( $atts ) {
extract( shortcode_atts( array(
‘id’ => ”,
‘class’ => ”,
‘style’ => ”,
‘type’ => ‘post’,
‘count’ => ”,
‘category’ => ”,
‘offset’ => ”,
‘orientation’ => ”,
‘no_image’ => ”,
‘fade’ => ”,
‘enable_excerpt’ => ‘true’
), $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’;
$enable_excerpt = ( $enable_excerpt == ‘true’ ) ? true: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}”
) );if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
$content_excerpt = get_the_excerpt();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’;
}endwhile; endif; wp_reset_postdata();
$output .= ‘</div>’;
return $output;
}add_action(‘wp_head’, ‘change_recent_posts_to_v2’);
function change_recent_posts_to_v2() {
remove_shortcode( ‘x_recent_posts’ );
add_shortcode( ‘x_recent_posts’, ‘x_shortcode_recent_posts_v2code’ );
}// Excerpt Custom Length
// =============================================================================
function x_excerpt_length( $length ) {
return 30;
}
add_filter( ‘excerpt_length’, ‘x_excerpt_length’ );July 21, 2016 at 10:51 pm #1098155
LelyModeratorHello Mal,
Thanks for posting in.
Please use the following code instead:// Recent Post Based on Character // ============================================================================= function x_shortcode_recent_posts_v2code( $atts ) { extract( shortcode_atts( array( 'id' => '', 'class' => '', 'style' => '', 'type' => 'post', 'count' => '', 'category' => '', 'offset' => '', 'orientation' => '', 'show_excerpt' => 'true', 'no_sticky' => '', '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'; $show_excerpt = ( $show_excerpt == 'true' ); $no_sticky = ( $no_sticky == 'true' ); $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' => $no_sticky ) ); 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-full' ); $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'; } $excerpt1 = get_the_content(); $excerpt1 = strip_shortcodes($excerpt1); $excerpt1 = strip_tags($excerpt1); $excerpt1 = substr($excerpt1, 0, 20); $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p>' . preg_replace('/<a.*?more-link.*?<\/a>/', '', $excerpt1 ) . '</p></div>' : ''; $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', 'cornerstone' ), 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>' . $excerpt . '</div>' . '</div>' . '</article>' . '</a>'; endwhile; endif; wp_reset_postdata(); $output .= '</div>'; return $output; } add_action('wp_head', 'change_recent_posts_to_v2'); function change_recent_posts_to_v2() { remove_shortcode( 'x_recent_posts' ); add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v2code' ); }By default, it will show excerpt. Please use shortcode if you want it off:
[x_recent_posts show_excerpt="false"]
OR
[x_recent_posts show_excerpt="true"]
Check this line if you want to adjust the length:
$excerpt1 = substr($excerpt1, 0, 20);
Hope this helps.July 23, 2016 at 9:39 am #1099893
ironmalParticipantThanks for the fix… but I still have uneven vertical space using the horizontal recent post “feature”. Attaching screen shot. Thanks –
July 23, 2016 at 10:32 am #1099916
ThaiModeratorHi There,
Please add the following CSS under Customizer > Custom > Global CSS:
@media (min-width: 980px){ .home #x-section-3 .x-recent-posts .x-recent-posts-content { min-height: 352px; } }Hope it helps 🙂
July 25, 2016 at 1:33 pm #1102288
ironmalParticipantNice efforts from all support people and I’m grateful for the ideas but I’m going to give up on getting this to work with the X-Theme. This is a problem that css people have worked on for literally 8 years with WordPress and some themes have nailed it but it’s sophisticated particularly as the browser width changes. You want the bottoms to be even using semantic code without arbitrarily forcing a minimum fixed vertical height, you don’t want to clobber and truncate the final word when it reaches the character limit. All the vertical columns in a container have to be measured and the exact vertical length of the largest is applied to the others. OK please close this one. Thank You !
July 26, 2016 at 1:36 am #1103008
Paul RModeratorYou’re welcome! 🙂
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1097749 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
