Tagged: x
-
AuthorPosts
-
June 10, 2016 at 10:02 am #1035971
Chris FParticipantHi there,
I had received some great support a few weeks ago which help me get my recent posts shortcode working just right. It’s able to filter by tag, custom post type, and show excerpts.
I have a new client who would like the same functionality so I figured I’d just bring over the code in the functions.php and use the same shortcode as the other site. Unfortunately, it’s not working properly and won’t show an excerpt from the post. Well, it won’t show the one automatically pulled from the first few lines of the post but it will show a custom/manually added excerpt.
If anyone has any idea as to why it might not be working on this additional site, I’d really appreciate the insight!
Cheers!
—-
Sample Test Page: http://angstrom.cssdesign.ca/test
Shortcode:
[x_recent_posts type=”posts” count=”3″ orientation=”horizontal” no_image=”false” enable_excerpt=”true”]Functions.php code:
function x_shortcode_recent_posts_v2code( $atts ) {
extract( shortcode_atts( array(
‘id’ => ”,
‘class’ => ”,
‘style’ => ”,
‘type’ => ‘post’,
‘count’ => ”,
‘category’ => ”,
‘offset’ => ”,
‘orientation’ => ”,
‘enable_excerpt’ => ‘false’,
‘no_sticky’ => ”,
‘no_image’ => ”,
‘fade’ => ”,
‘tag’ => ”
), $atts, ‘x_recent_posts’ ) );$allowed_post_types = apply_filters( ‘cs_recent_posts_post_types’, array( ‘post’ => ‘post’, ‘pl_publications’ => ‘pl_publications’, ‘pl_armedconflict’ => ‘pl_armedconflict’ ) );
$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’;
$enable_excerpt = ( $enable_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,
‘tag’ => $tag
) );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 = ( $enable_excerpt ) ? ‘<div class=”x-recent-posts-excerpt”><p>’ . preg_replace(‘/<a.*?more-link.*?<\/a>/’, ”, cs_get_raw_excerpt() ) . ‘</p></div>’ : ”;
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’ );
remove_shortcode( ‘x_recent_posts’ );
remove_shortcode( ‘cs_recent_posts’ );
add_shortcode( ‘recent_posts’, ‘x_shortcode_recent_posts_v2code’ );
add_shortcode( ‘x_recent_posts’, ‘x_shortcode_recent_posts_v2code’ );
add_shortcode( ‘cs_recent_posts’, ‘x_shortcode_recent_posts_v2code’ );
}June 10, 2016 at 4:48 pm #1036484
FriechModeratorHi There,
Thanks for writing in! But instead of using a custom code, since we do have this extensions now. We advice to use either the Essential Grid or The Grid to output a customise grid of posts.
Cheers!
June 14, 2016 at 5:51 am #1041131
Chris FParticipantOkay, we’ll give it a go and see if we can find something that works. Thanks.
June 14, 2016 at 9:28 am #1041445
JoaoModeratorHi Chris
Let us know how it goes and reach us if you have any questions.
Thanks
Joao
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1035971 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
