Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #243888

    matthewhickey
    Participant

    WOW talk about bad luck, I went to customize-editor, functions.php added:

    
    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 ) );

    now I can’t access my site at all. How do I fix this? I consider this a SERIOUS problem. I just added the code at the end of the functions.php

    #243929

    Nico
    Moderator

    Hi There,

    @matthewhickey would you mind opening a new thread for that new issue. For us, could ask your admin credentials and ftp. Because if you post it here, the previous thread owner could see your details even in private reply.

    You could also share on the new thread on what were the past things you did to your site that cause that may cause the issue.

    Thank you so much.

    #251379

    Rich H
    Participant

    This works great, how do I make the excerpt longer tho?

    #251540

    Zeshan
    Member

    Hi Rich,

    Thanks for writing in!

    Add following in your child theme’s functions.php file:

    // Excerpt Custom Length
    function custom_excerpt_length(  ) {
      return 20;
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
    

    Change 20 to your desired excerpt words length.

    Thanks!

    #278407

    Sean S
    Participant

    Just an FYI, I added the enable excerpt php and the excerpt length and everything worked PERFECTLY. Thank you very much and you guys should add this to X. Great feature.

    For the people who read all this and have problems, look below.

    [recent_posts type=”post” category=”vou-me-casar,fotos-de-casamento” count=”3″ offset=”1″ orientation=”horizontal” enable_excerpt=”true” no_image=”false” fade=”true”]

    Look at the quotes, they are wrong. Below is correct.

    [recent_posts type=”post” category=”vou-me-casar,fotos-de-casamento” count=”3″ offset=”1″ orientation=”horizontal” enable_excerpt=”true” no_image=”false” fade=”true”]

    #278410

    Sean S
    Participant

    Well, apparently both of those quotes are correct… BUT.. pay attention to the quotes. lol.

    #278419

    Friech
    Moderator

    Hi There,

    Both shortcode above is correct, they just have a different format of quotes. It’s a best practice to wrap in <code> tag when posting a snippet of code.

    <code>[recent_posts type="post" category="vou-me-casar,fotos-de-casamento" count="3" offset="1" orientation="horizontal" enable_excerpt="true" no_image="false" fade="true"]</code>

    Cheers!

    #279000

    Sean S
    Participant

    Thanks. While I have you here, I am redoing our company blog from top to bottom. Cleaning out old and thin content, updating, etc. I used the recent post shortcode and added both the excerpt and length to the functions.php and everything worked fine.

    Problems:
    As I go through each post, I am changing up the post using visual composer, and now the excerpt no longer shows.

    Also, the excerpt length for the recent posts that was added to the functions.php overrides the excerpt length in the customizer. I would be nice to be able to control the excerpt on recent posts shortocde and what shows up on the category page separately.

    #279187

    Rad
    Moderator

    Hi Sean,

    That’s because enable_excerpt is never part of visual composer’s recent posts shortcode. It’s only applied on the shortcode and not on visual composer.

    If you wish to force excerpt even on visual composer generated shortcode, then change this :

    . ( $enable_excerpt ? '<span class="x-recent-posts-excerpt">' . strip_tags( get_the_excerpt() ) . '</span>' : '' )
    

    to this

    . '<span class="x-recent-posts-excerpt">' . strip_tags( get_the_excerpt() ) . '</span>'

    About the excerpt length, you can try this https://theme.co/x/member/forums/topic/customize-the-post-presentation/page/2/#post-169738

    Hope this helps.

    #290420

    David B
    Participant

    Sad to see that this feature didn’t make it into Cornerstone. Would it be possible for you to revisit how to incorporate this into the new Cornerstone interface? My site isn’t ‘live’. I have to edit the hosts file to see it, as it’s being build while another version is live. Not sure if there’s a way you could give me some direction on a way to get a excerpt of x length into the recent posts?

    Best!

    #291221

    Paul R
    Moderator

    Hi David,

    To add an excerpt, you can add the code below in your child theme’s functions.php file

    
    function x_shortcode_recent_posts_v2code( $atts ) {
      extract( shortcode_atts( array(
        'id'          => '',
        'class'       => '',
        'style'       => '',
        'type'        => 'post',
        'count'       => '',
        'category'    => '',
        'enable_excerpt' => '',
        'offset'      => '',
        'orientation' => '',
        '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';
      $no_image      = ( $no_image    == 'true'      ) ? $no_image : '';
      $fade          = ( $fade        == 'true'      ) ? $fade : 'false';
      $enable_excerpt = ( $enable_excerpt == 'true'      ) ? true : 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();
          $content_excerpt = get_the_excerpt();
          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>'
                            . ( $enable_excerpt ? '<span class="x-recent-posts-excerpt">' . strip_tags($content_excerpt ) . '</span>' : '' )
                         . '</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' );
    }
    
    

    After that, you can add enable_excerpt=”true” in your recent posts shortcode to show the excerpt.

    eg.

    
    [x_recent_posts type="post" count="4" enable_excerpt="true"]
    

    With regards to excerpt length, you can change it under blog > content in the customizer.

    http://screencast.com/t/6SEnOSj00Fl

    Hope that helps.

    #366220

    nowherean
    Participant

    Hello, I’m having issue displaying the excerpts after 1) Enabling the Child theme 2) Adding the code you have provided into my functions.php 3) Adding enable_excerpt=”true” string to my [x_recent_posts type=”post” enable_excerpt=”true” count=”3″ offset=”” category=”” orientation=”horizontal” no_image=”false” fade=”true”]

    Nothing is showing up still. Please advise what to do next? I’m using Icon stack at the moment. The site is on my local server.

    I’m also really surprised you didn’t include options for showing excerpts in posts. Its such an important aspect for many bloggers. Now so many people have to deal with workarounds and waste so much time!

    #366428

    Christopher
    Moderator

    Hi there,

    Please make sure you are fully updated.
    Please open a new topic and provide us with URL, FTP and login credentials in there.

    We need you to upload your site to a temporary domain as we can’t investigate the issue on local.

    Thanks.

    #371211

    rabbler
    Participant

    Hi guys does this ability to enable excerpts work with cornerstone and the latest theme versions?

    Thanks

    #371353

    HannaHa
    Participant

    I would really like to see this feature too! I tried updating the functions.php but then the whole site went blank so I restored it to a previous backup…