Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #96050
    Innovata
    Participant

    Hello,

    On the homepage of nieuw.teunvandekeuken.nl I’m using the shortcode recent posts without the featured image. Now only the titles and dates of the posts are published. But I also want to ad a short summary / excerpt under the titles with a read more link. Is this possible?

    Thanks in advance.

    #96052
    Christian
    Moderator
    #96065
    Innovata
    Participant

    I followed the instruction in the link, but nothing happens. Still no excerpts under the post titles.

    #96077
    Paul R
    Moderator

    Hi,

    Please note that switching from classic to visual composer may remove the enable_excerpt attribute since it is not a default option.

    Would you mind trying the code below.

    
    [recent_posts enable_excerpt="true" type="post" orientation="horizontal" no_image="true" category="Columns"]
    

    Thank you.

    #96080
    Innovata
    Participant

    Unfortenately. Not working.

    #96082
    Christopher
    Moderator

    Hi there ,

    You might want to try this plugin to add excerpt:
    http://wordpress.org/plugins/advanced-excerpt/.

    Hope it helps.

    #96108
    Innovata
    Participant

    I installed the plugin, but only has effect on the blog index page. The recent posts on the homepage still don’t have an excerpt.

    #96135
    Zeshan
    Member

    Hi Innovata!

    Thank you for writing in!

    Instead of using about codes, try adding the following code in your child theme’s functions.php file and see if it enables excerpt in your [recent_posts] shortcode:

    // Recent Posts - Adding EXCERPT to recent_posts shortcode
    // =============================================================================
    
    function x_shortcode_recent_posts2( $atts ) {
      extract( shortcode_atts( array(
        'id'          => '',
        'class'       => '',
        'style'       => '',
        'type'        => '',
        'count'       => '',
        'category'    => '',
        'offset'      => '',
        'orientation' => '',
        'no_image'    => '',
        'fade'        => ''
      ), $atts ) );
    
      $id            = ( $id          != ''          ) ? 'id="' . esc_attr( $id ) . '"' : '';
      $class         = ( $class       != ''          ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
      $style         = ( $style       != ''          ) ? 'style="' . $style . '"' : '';
      $type          = ( $type        == 'portfolio' ) ? 'x-portfolio' : 'post';
      $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';
    
      $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} 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_output       = '<div class="x-recent-posts-img">' . get_the_post_thumbnail( get_the_ID(), 'entry-' . x_get_option( 'x_stack', 'integrity' ) . '-cropped', NULL ) . '</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"', '__x__' ), 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>'
                           . do_shortcode('[gap size="10px"]') . '<p>' . get_the_excerpt() . '</p>'
                           . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
                         . '</div>'
                       . '</div>'
                     . '</article>'
                   . '</a>';
    
        endwhile; endif; wp_reset_postdata();
    
      $output .= '</div>';
    
      return $output;
    }
    
    add_filter('init', function() {
    	remove_shortcode( 'recent_posts' );
    
    	add_shortcode( 'recent_posts', 'x_shortcode_recent_posts2' );
    });
    

    Hope this helps. 🙂

    Thank you.

    #96154
    Innovata
    Participant

    With or without using the plugin ‘Advanced excerpt’?

    #96158
    Innovata
    Participant

    I deactivated the plugin and added the code to the child’s function.php. No I can see the excerpts on the homepage of nieuw.teunvandekeuken.nl, but the styling is not ok. Could you have a look and explain what’s wrong?

    #96173
    Paul R
    Moderator

    Hi,

    Would you mind taking a look if that is how you would like it to work.

    http://nieuw.teunvandekeuken.nl/

    The first code given was working except that you had pretty quotes.
    I would like to suggest in copying shortcodes it is best to paste it first in notepad to
    remove some formmating.

    Thank you.

    #96188
    Innovata
    Participant

    Much better, but a few things:

    – How do I get the ‘read more’ link under (with a linebreak) under the excerpts?
    – How do I change the link color of the ‘read more’ link in these excerpts?
    – Is the summary also working for this?

    #96224
    Christopher
    Moderator

    Hi,
    Please add this code in function.php in child theme

    function x_shortcode_recent_posts2( $atts ) {
      extract( shortcode_atts( array(
        'id'          => '',
        'class'       => '',
        'style'       => '',
        'type'        => '',
        'count'       => '',
        'category'    => '',
        'offset'      => '',
        'orientation' => '',
        'no_image'    => '',
        'fade'        => ''
      ), $atts ) );
    
      $id            = ( $id          != ''          ) ? 'id="' . esc_attr( $id ) . '"' : '';
      $class         = ( $class       != ''          ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
      $style         = ( $style       != ''          ) ? 'style="' . $style . '"' : '';
      $type          = ( $type        == 'portfolio' ) ? 'x-portfolio' : 'post';
      $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';
    
      $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} 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_output       = '<div class="x-recent-posts-img">' . get_the_post_thumbnail( get_the_ID(), 'entry-' . x_get_option( 'x_stack', 'integrity' ) . '-cropped', NULL ) . '</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"', '__x__' ), 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>'
                           . do_shortcode('[gap size="10px"]') . '<p>' . get_the_excerpt() . '</p>'
                           .'<span>'.'<a href="<?php the_permalink()?>">'.permalink.'</a>'.'</span>'
                           . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
                         . '</div>'
                       . '</div>'
                     . '</article>'
                   . '</a>';
    
        endwhile; endif; wp_reset_postdata();
    
      $output .= '</div>';
    
      return $output;
    }
    
    add_filter('init', function() {
      remove_shortcode( 'recent_posts' );
    
      add_shortcode( 'recent_posts', 'x_shortcode_recent_posts2' );
    });

    Hope it helps.

    #96240
    Innovata
    Participant

    Oh no, now it’s displayed totally wrong again with this code!

    #96288
    Zeshan
    Member

    Hi Innovata!

    Thank you for writing in!

    The above given code shouldn’t make any issue, 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 credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    Thanks!

  • <script> jQuery(function($){ $("#no-reply-96050 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>