Tagged: x
-
AuthorPosts
-
June 23, 2016 at 7:48 am #1056240
Sarah WParticipantHi,
I’m using Icon and I would like my ‘recent posts’ to display a small amount of text and ‘read more’.
Is this possible?
Thank youJune 23, 2016 at 8:13 am #1056273
Sarah WParticipantFurther to that, actually what I want…or rather the client wants….is for the ‘recent posts’ to display
a thinner image and some text with ‘read more’.
So half image, half text in the boxes.
Is this possible?Thank you!
June 23, 2016 at 8:14 am #1056275
Sarah WParticipantThis reply has been marked as private.June 23, 2016 at 10:11 am #1056451
DarshanaModeratorHi there,
Thanks for writing in! Please refer to the following post for a possible implementation (https://community.theme.co/forums/topic/adding-blog-text-and-read-more-link-to-recent-posts/#post-810125).
Hope that helps.
June 23, 2016 at 11:14 am #1056553
Sarah WParticipantIt does work, thanks. But is there a way of making the “Read More’ show up?
June 23, 2016 at 11:16 am #1056558
Sarah WParticipantAlso is there a way of reducing the height of the featured image on the ‘recent posts’ box?
Thank youJune 23, 2016 at 5:21 pm #1057091
JadeModeratorHi Sarah,
Please try this code to add the read more:
// ============================================================================= // 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>' . '<span class="x-recent-post-read-more"><a href="' .the_permalink() .'">Read More</a></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' ); }Then add this code in the CSS customizer:
.x-recent-posts .x-recent-posts-img { padding-bottom: 45.25%; }Hope this helps.
July 1, 2016 at 11:48 am #1068576
Sarah WParticipantHi,
I’m afraid it doesn’t.
I had to replace the original functions.php via ftp as it initially caused an internal error 500.
Then I tried it again and it went nuts; separated the boxes, put weird white lines in and put the ‘read
more’ in another box on the other side of the page.
You are welcome to go into the site and try putting your code it into the functions.php, as maybe I’m missing something.
But I can’t see what I’ve done wrong.July 1, 2016 at 11:49 am #1068580
Sarah WParticipantThis reply has been marked as private.July 1, 2016 at 6:59 pm #1068979
RadModeratorHi Sarah,
Recent post item is a link itself, adding read more with another link will break it. Link within a link isn’t possible.
Try this one,
// ============================================================================= // 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>' . '<span class="x-recent-post-read-more">Read More</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' ); remove_shortcode( 'recent_posts' ); remove_shortcode( 'cs_recent_posts' ); add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_excerpt' ); add_shortcode( 'recent_posts', 'x_shortcode_recent_posts_excerpt' ); add_shortcode( 'cs_recent_posts', 'x_shortcode_recent_posts_excerpt' ); }Thanks!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1056240 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
