Tagged: x
-
AuthorPosts
-
May 9, 2016 at 6:47 am #982084
Hi X
I’ve seen some input on this before but because they were quite old threads I thought I’ll create a new one. I use the latest of all, WordPress, X theme (Integrity), and Cornerstone. I want to add a custom post type posts to some pages built with Cornerstone. The post types belong to certain custom taxonomy.
Custom post type is “Apps”, custom taxonomy is “App Category” and come under it are “Gone Free”, “On Sale”, and “New Apps”. So I want to be able to choose posts to show in my Cornerstone built page, whether from gone-free, on-sale, or new-apps.
Hope that makes sense.
Thanks in advance…
May 9, 2016 at 8:23 am #982225Hi There,
Please add the following code under functions.php locates in your child theme:
function x_shortcode_recent_posts_v2( $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 : ''; if( $type == 'post' ){ $category_type = 'category_name'; } elseif ($type == 'x-portfolio') { $category_type = 'portfolio-category'; } elseif ($type == 'apps') { $category_type = 'app_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>' . preg_replace('/<a.*?more-link.*?<\/a>/', '', 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('init', 'override_shortcode' ); function override_shortcode(){ remove_shortcode( 'x_recent_posts' ); add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v2' ); }
Then find and replace the
apps
&app_category
with your custom post type & taxonomy slug.Let us know how it goes!
May 9, 2016 at 9:41 am #982356Thanks Thai. It didn’t work.
May 9, 2016 at 10:35 am #982451Hi there,
Would you mind providing us with login credentials so we can take a closer look? 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.
May 9, 2016 at 10:47 am #982472This reply has been marked as private.May 9, 2016 at 12:44 pm #982674This reply has been marked as private.May 9, 2016 at 1:13 pm #982714Thanks Thai. That works only when using the shortcode, it doesn’t appear in the list of cornerstone widget post types (see attachment).
Thanks
May 9, 2016 at 11:12 pm #983480Hello There,
Thank you for the screenshot.
Yes, it will only work for the shortcodes.
The Cornerstone setting to allow post type does not include in the recent posts element. In this setting, you are enabling Cornerstone to be available as an editor in this post type. It has nothing to do with the recent posts element. With the recent posts element on the other hand, we have designed it to display post and portfolio items by default. You can extend to include other posts type by adding inserting the following code in your child theme’s functions.php file;function add_event_post_type( $types ) { $types['post_type_name'] = 'app'; return $types; } add_filter( 'cs_recent_posts_post_types', 'add_event_post_type', 999 );
Hope this helps.
May 10, 2016 at 1:46 am #983612Thanks Lely. That worked.
May 10, 2016 at 2:43 am #983651You are welcome!
Glad that it helped. Feel free to let us know if you face any other issue. We’ll be happy to assist you.
Thanks for using X.
Cheers!
-
AuthorPosts