-
AuthorPosts
-
June 22, 2015 at 10:34 am #309477
glennyboyParticipantHi
Additional Custom Posts types don’t seem to appear/register in X Theme or are not available in the ‘Recent Posts’ widget? I only ever see ‘Posts’ and ‘portfolio”?
Thanks
Glennyboy`
June 22, 2015 at 11:24 am #309512
glennyboyParticipant… also the Recent Posts plugin and associated shortcake ate limited to 4 posts whereas I need to show x posts or ‘Show All’. How can I achieve that also please?
June 22, 2015 at 12:40 pm #309590
ThaiModeratorHi There,
Thanks for writing in.
This is only possible if you override the x_recent_post shortcode by customizing your own. Please use following PHP code in your child theme’s functions.php file:
function x_shortcode_recent_posts_override( $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', 'your-post-type' => 'your-post-type' ) ); $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}", '' ) ); 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>' . '</div>' . '</div>' . '</article>' . '</a>'; endwhile; endif; wp_reset_postdata(); $output .= '</div>'; return $output; } add_action('init', 'x_overwrite_shortcode'); function x_overwrite_shortcode() { remove_shortcode( 'x_recent_posts' ); add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_override' ); }You can replace the your-post-type with your new post type slug.
… also the Recent Posts plugin and associated shortcake ate limited to 4 posts whereas I need to show x posts or ‘Show All’. How can I achieve that also please?
=> Usage: [x_recent_posts count=”-1″ type=”your-type”]
Hope it helps.
June 23, 2015 at 5:56 am #310328
glennyboyParticipantHi Guys
Can you look to add this as a feature to ‘element’ as having a restriction to 4 posts is very limiting.
I figured out the shortcake with -1 but actually what the output then does is bunch posts up with responsive sizing issues.
In relation to specifying post type in shortcode- my test it simply defaults to ‘posts’ and again I think that has something to do with a post registration issue into X. Not 100% but that does seem to be the case as ‘posts’ and ‘portfolio’ do show – nothing else.
Right now as I want adopt ‘out of the box elements’ what I am doing is adding multiple recent post elements and adding an incremental +4 on each. That creates a pseudo layout which is by no means ideal, but it’s the best method for consistent layout right now.
Cheers
Glennyboy
June 23, 2015 at 8:06 am #310481
ZeshanMemberHi Glennyboy,
We certainly appreciate the feedback! This is something we can add to our list of feature requests. This way it can be taken into consideration for future development. All of these items are discussed with our team internally and prioritized based on the amount of interest a particular feature might receive.
In regard to the custom post types, right now, Recent Posts shortcode only work with posts and “X Portfolio” post type. Integrating a different custom post type might be possible with custom development and given above, but would be outside the scope of support we can offer you. 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.
August 5, 2015 at 2:57 pm #351165
motivteamParticipantHi–just chiming in to say that I am also having the issue where I added the above code into my Functions file (customized according to directions), but the custom post type still won’t display. Agree with Glennyboy, this be an awesome addition if possible!
August 5, 2015 at 5:05 pm #351276
LelyModeratorHello There,
Would you mind providing us with login credentials so we can take a closer look to your settings? To do this, you can make a post with the following info:
– Link to your site
– WordPress Admin username / password
– FTP credentialsDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
January 14, 2016 at 1:51 am #745560
MiltonParticipantHi guys,
I’m also trying to use some Custom Post Types in recent posts. But it’s unclear to me if the code shown on this post is supposed to work. I have included it but with no results. Is there anything else that needs to be done?
January 14, 2016 at 2:12 am #745578
Rue NelModeratorHello Milton,
Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.
Once the child theme is active and ready, please add the following code in your child theme’s functions.php
function add_event_post_type( $types ) { $types['post_type_name'] = 'post_type_name'; return $types; } add_filter( 'cs_recent_posts_post_types', 'add_event_post_type', 999 );If you have place the code right, you should be able to get something like this:

We would loved to know if this has work for you. Thank you.
February 18, 2016 at 11:13 pm #802779
k8.petersonParticipantJust wanted to say that it took me figuring out that the child theme that came with X was broken, but using these two code chunks together worked for me.
for the second one (function add_event_post_type), switch ‘post_type_name’ with your post slug. as opposed to the first, which is ‘your-post-type’ – pretty simple but could trip someone up.
February 19, 2016 at 6:10 am #803158
LelyModeratorHello There,
Glad that this has work for you.
Thank you for the clarification.Always,
X -
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-309477 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
