Tagged: x
-
AuthorPosts
-
February 6, 2017 at 12:21 pm #1360007
KeanuParticipantHi there,
I’ve been following this post here https://community.theme.co/forums/topic/add-excerpt-to-recent-posts-shortcode/ which adds in a method for recent-posts to show the except, which is great, however I need to add a button to the bottom of it. Tried various different methods such as echo do_shortcode etc, but it isn’t having any of it.
Please can you provide me a way to display a button below the post?
Thanks!!!
Kind Regards,
-JoshFebruary 6, 2017 at 1:13 pm #1360061
RahulModeratorHi There,
Greetings!
Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.
February 6, 2017 at 2:50 pm #1360171
KeanuParticipantThis reply has been marked as private.February 6, 2017 at 11:23 pm #1360684
ChristopherModeratorHi there,
Please update your code in functions.php file to :
// ============================================================================= function x_shortcode_recent_posts_v2code( $atts ) { extract( shortcode_atts( array( 'id' => '', 'class' => '', 'style' => '', 'type' => '', 'count' => '', 'category' => '', 'enable_excerpt' => '', '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'; $enable_excerpt = ( $enable_excerpt == 'true' ) ? true : 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-' . get_theme_mod( 'x_stack' ) . '-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>' . '<span class="x-recent-posts-date">' . get_the_date() . '</span>' . ( $enable_excerpt ? '<span class="x-recent-posts-excerpt">' . strip_tags( get_the_excerpt() ) . '</span>' : '' ) .'<div>' . __( 'Read More', '__x__' ) .'</div>' . '</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' ); }Hope it helps.
February 7, 2017 at 4:56 am #1360946
KeanuParticipantHi Christopher,
Thank you for the code! Sadly that seems to have removed everything apart from the title of the recent post though! (Page in question is the courses page) Any ideas?
Kind Regards,
-JoshFebruary 7, 2017 at 5:52 am #1360999
Paul RModeratorHi Josh,
It’s because of this css.
.x-recent-posts .x-recent-posts-img { padding-bottom: 0px; } .x-recent-posts .x-recent-posts-date { display: none; }You can remove it in your Custom CSS if you want the image and date to show up.
Thanks
February 7, 2017 at 7:15 am #1361093
KeanuParticipantHi Paul,
That only shows the date on the posts which we don’t need, but no excerpt like before. However has fixed the images. I think it may well be the code provided from before. I did make a backup of the old code. I’ve swapped back to the old code, and just added in the .'<div>’ . __( ‘Read More’, ‘__x__’ ) .'</div>’ line, which has worked, however is there any way to swap it over to a x-button instead? Litterly just need to add this html (below) but whenever I do, it completely messes up the page!
<a class="x-btn x-btn-flat x-btn-rounded x-btn-regular" href="" target="_blank" data-options="thumbnail: ''">Get your copy here<i class="x-icon mvn mls mrn x-icon-chevron-right" data-x-icon="" aria-hidden="true"></i></a>(something to do with the data-options=”thumbnail: ” I think?? as i’m not able to save the code in AceIDE unless I remove it!)
On a slight side note, is there anyway to reverse the order in which recent posts displays it’s items? I figured out that it displays the most recent post first, but is there any way to swap that so it shows oldest first?
Thanks!
Kind Regards,
-JoshFebruary 7, 2017 at 7:58 am #1361137
Paul RModeratorHi Josh,
Please replace your code with this.
function x_shortcode_recent_posts_v2code( $atts ) { extract( shortcode_atts( array( 'id' => '', 'class' => '', 'style' => '', 'type' => 'post', 'count' => '', 'category' => '', 'offset' => '', 'orientation' => '', 'show_excerpt' => 'false', '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-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'; } $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p>' . cs_get_raw_excerpt() . '</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' ); }Then use this shortcode
[x_recent_posts count="4" show_excerpt="true"]Hope that helps.
February 7, 2017 at 10:35 am #1361382
KeanuParticipantHi Paul,
That’s exactly the same code I had initially, minus the “read more” at the bottom? The code I have right now works, the problem is that I’d like to change the “read more” to a button instead of text.
// Add excerpt to recent posts // ============================================================================= function x_shortcode_recent_posts_v2code( $atts ) { extract( shortcode_atts( array( 'id' => '', 'class' => '', 'style' => '', 'type' => '', 'count' => '', 'category' => '', 'enable_excerpt' => '', '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'; $enable_excerpt = ( $enable_excerpt == 'true' ) ? true : 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-' . get_theme_mod( 'x_stack' ) . '-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>' . '<span class="x-recent-posts-date">' . get_the_date() . '</span>' . ( $enable_excerpt ? '<span class="x-recent-posts-excerpt">' . strip_tags( get_the_excerpt() ) . '</span>' : '' ) .'<div>' . __( 'read more', '__x__' ) .'</div>' . '</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( 'recent_posts' ); add_shortcode( 'recent_posts', 'x_shortcode_recent_posts_v2code' ); }Above is the code I have right now
.'<div>' . __( 'read more', '__x__' ) .'</div>'That’s the line that i’d like to change to a button.
Litterly just need to add the html displayed below instead of the “read more” but whenever I do, it completely messes up the page!
<a class="x-btn x-btn-flat x-btn-rounded x-btn-regular" href="" target="_blank" data-options="thumbnail: ''">Get your copy here<i class="x-icon mvn mls mrn x-icon-chevron-right" data-x-icon="" aria-hidden="true"></i></a>I think it is something to do with the data-options=”thumbnail: ”” as i’m not able to save the code in AceIDE unless I remove it!
On a slight side note, is there anyway to reverse the order in which recent posts displays it’s items? I figured out that it displays the most recent post first, but is there any way to swap that so it shows oldest first?
Thanks!
Kind Regards,
-JoshFebruary 7, 2017 at 9:33 pm #1362241
FriechModeratorHi Josh,
What makes the button looks like a button is the STYLES that is applied on it. So instead of editing the HTML markup, apply the button classes on the read more div.
e.g.
.'<div class="x-btn x-btn-flat x-btn-rounded x-btn-regular">' . __( 'read more', '__x__' ) .'</div>'To show the oldest post first, edit this block of the code:
$q = new WP_Query( array( 'orderby' => 'date', 'post_type' => "{$type}", 'posts_per_page' => "{$count}", 'offset' => "{$offset}", "{$category_type}" => "{$category}" ) );to this:
$q = new WP_Query( array( 'orderby' => 'date', 'order' => 'ASC', 'post_type' => "{$type}", 'posts_per_page' => "{$count}", 'offset' => "{$offset}", "{$category_type}" => "{$category}" ) );Hope it helps, Cheers!
February 8, 2017 at 10:00 am #1362974
KeanuParticipantWhy didn’t I think of that… Bah! All working, thank you very much for your help again!!
I think this topic can be closed off now!
Kind Regards,
-JoshFebruary 8, 2017 at 12:39 pm #1363194
RupokMemberGlad that you are all set now Josh. Have a nice day!
February 22, 2017 at 11:13 am #1381635
KeanuParticipantHaving one more problem with this. It seems to be displaying “read more” above the button? How do I go around removing this please?
Thanks!
Kind Regards,
-JoshFebruary 22, 2017 at 8:29 pm #1382238
Rue NelModeratorHello Josh,
Thanks for updating in! You can modify the excerpt read more, by adding the following code in your child theme’s functions.php file
// Excerpt More String // ============================================================================= if ( ! function_exists( 'x_excerpt_string' ) ) : function x_excerpt_string( $more ) { $stack = x_get_stack(); if ( $stack == 'integrity' ) { return ' ...'; } else if ( $stack == 'renew' ) { return ' ... <a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>'; } else if ( $stack == 'icon' ) { return ' ...'; } else if ( $stack == 'ethos' ) { return ' ...'; } } add_filter( 'excerpt_more', 'x_excerpt_string' ); endif;Hope this helps. Kindly let us know.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1360007 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
