Tagged: x
-
AuthorPosts
-
August 10, 2016 at 6:06 pm #1126296
LewisWallisParticipantHi there
On the homepage of the website that I am building (using the Renew Stack) I am using Cornerstone’s recent post element to display recent portfolio entries. I would like to add a button to the recent posts so that it looks like the attached screen shot.
Many thanks
Lewis
August 10, 2016 at 6:09 pm #1126299
LewisWallisParticipantThis reply has been marked as private.August 11, 2016 at 12:50 am #1126769
Rue NelModeratorHello There,
Thanks for writing in! What you are trying to accomplish requires a template customization, we would like to suggest that you use 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.
After the child theme is set up, please add the following code in your child theme’s functions.php file
// Updated Recent Post and Portfolio element // ============================================================================= function updated_shortcode_recent_posts( $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 : ''; $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'; } if ( get_post_type() == 'x-portfolio' ) { $button = '<span class="x-btn x-btn-square x-btn-regular x-btn-block">View Investment</span>'; } else { $button = ''; } // $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 . $button . '</div>' . '</div>' . '</article>' . '</a>'; endwhile; endif; wp_reset_postdata(); $output .= '</div>'; return $output; } add_action('init', 'apply_custom_shortcode_recent_posts'); function apply_custom_shortcode_recent_posts() { remove_shortcode( 'x_recent_posts' ); add_shortcode( 'x_recent_posts', 'updated_shortcode_recent_posts' ); } // =============================================================================We would loved to know if this has work for you. Thank you.
August 12, 2016 at 10:31 am #1128853
LewisWallisParticipantThat worked a treat! Many thanks
August 12, 2016 at 11:33 am #1128927
Prasant RaiModeratorYou are most welcome. 🙂
August 12, 2016 at 6:34 pm #1129321
LewisWallisParticipantThanks again for your excellent solution. I now have a follow on question, which is very similar to the initial question. In the initial question you gave me the relevant php code to add a button to the Recent Post element. How do I now add that same button to the portfolio thumbnails on this page: http://phillipshawinvestments.co.uk/fixed-term-investments/ (you will need to login to see this page – my log in details can be seen above in previous message).
Many thanks
Lewis
August 13, 2016 at 1:01 am #1129652
ChristopherModeratorHi there,
Copy content-portfolio.php from framework/views/renew and put it in the same path inside child theme, replace existing code with following :
<?php // ============================================================================= // VIEWS/RENEW/CONTENT-PORTFOLIO.PHP // ----------------------------------------------------------------------------- // Portfolio post output for Renew. // ============================================================================= ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php if ( ! x_is_portfolio_item() ) : ?> <div class="entry-featured"> <?php x_portfolio_item_featured_content(); ?> <div class="entry-cover"> <div class="entry-cover-content"> <span><?php echo get_post_meta( get_the_ID(), '_x_portfolio_media', true ); ?></span> <h2 class="entry-title entry-title-portfolio"> <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php x_the_alternate_title(); ?></a> </h2> <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ); ?>">View Investment</a> <span><?php echo get_the_date( 'm.d.y' ); ?></span> </div> </div> </div> <?php endif; ?> <div class="entry-wrap cf"> <?php if ( is_singular() ) : ?> <div class="entry-info"> <div class="entry-featured"> <?php x_featured_portfolio( 'cropped' ); ?> </div> <header class="entry-header"> <h1 class="entry-title entry-title-portfolio"><?php the_title(); ?></h1> <?php x_renew_entry_meta(); ?> </header> <?php x_get_view( 'global', '_content', 'the-content' ); ?> </div> <div class="entry-extra"> <?php x_portfolio_item_tags(); ?> <?php x_portfolio_item_project_link(); ?> <?php x_portfolio_item_social(); ?> </div> <?php endif; ?> </div> </article>Hope it helps.
August 17, 2016 at 2:33 pm #1135648
LewisWallisParticipantAmazing thanks! I posted the same question previously (about a week ago) and the response I got was ‘this is outside the scope of support we can offer – you may wish to consult a developer’ – so, thanks so much for going the extra mile and giving me a useable solution.
August 17, 2016 at 4:53 pm #1135841
JadeModeratorYou’re most welcome Lewis.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1126296 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
