Viewing 2 posts - 1 through 2 (of 2 total)
  • Posted in: Atelier
  • #260173
    cfairi
    Member
    Post count: 129

    Hi, I would like to have an excerpt show up under related articles (on the blog).

    An example can be seen on this page: http://fairinachengjewellery.com/custom-jewellery/ring-without-borders/

    Attachments:
    You must be logged in to view attached files.
    #260185
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please use this custom code at functions.php of child theme.

    
    function sf_post_related_articles() {
    
                $related_articles_class = apply_filters( 'sf_post_related_articles_wrap_class', 'container' );
    			$related_articles_display_type = apply_filters( 'sf_related_articles_display_type', 'bold' );
    			$related_articles_excerpt_length = apply_filters( 'sf_related_articles_excerpt_length', 20 );
    			$list_class = 'posts-type-'.$related_articles_display_type;
    
    			if ($related_articles_display_type == "bold") {
    				$list_class .= ' no-gutters';
    			} else {
    				$list_class .= ' row';
    			}
    
                global $post;
    
                $args       = array();
                $tags       = wp_get_post_tags( $post->ID );
                $categories = get_the_category( $post->ID );
                if ( ! empty( $tags ) ) {
                    $tag_ids = array();
                    foreach ( $tags as $individual_tag ) {
                        $tag_ids[] = $individual_tag->term_id;
                    }
                    $args = array(
                        'tag__in'             => $tag_ids,
                        'post__not_in'        => array( $post->ID ),
                        'posts_per_page'      => 4, // Number of related posts to display.
                        'ignore_sticky_posts' => 1
                    );
                } else if ( ! empty( $categories ) ) {
                    $category_ids = array();
                    foreach ( $categories as $individual_category ) {
                        $category_ids[] = $individual_category->term_id;
                    }
    
                    $args = array(
                        'category__in'   => $category_ids,
                        'post__not_in'   => array( $post->ID ),
                        'posts_per_page' => apply_filters( 'sf_related_posts_count', 4 ), // Number of related posts that will be shown.
                        'orderby'        => 'rand'
                    );
                }
    
                $related_posts_query = new WP_Query( $args );
                if ( $related_posts_query->have_posts() ) {
                    echo '<div class="related-wrap">';
                    echo '<div class="related-articles ' . $related_articles_class . '">';
                    echo '<div class="title-wrap"><h3 class="spb-heading"><span>' . __( "Related Articles", "swiftframework" ) . '</span></h3></div>';
                    echo '<div class="related-items recent-posts '.$list_class.' clearfix">';
    
                    while ( $related_posts_query->have_posts() ) : $related_posts_query->the_post();
               //echo sf_get_recent_post_item( $post, $related_articles_display_type, $related_articles_excerpt_length, 'col-sm-3' );
                    echo   sf_get_post_item( $post, $related_articles_display_type, $show_title = "yes", $show_excerpt = "yes", $show_details = "no", $excerpt_length = "20", $content_output = "excerpt", $show_read_more = "no", $fullwidth = "col-sm-3" );
                    endwhile;
    
                    echo '</div>';
                    echo '</div>';
                    echo '</div>';
                }
                wp_reset_query();
            }

    Thanks
    Mohammad

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register