Recent posts show excerpt and include only one category

Hi,
Im trying to add excerpts to recent posts and only include one or two categories. Ive followed instructions in other posts and have the excerpts. But the category I want removed isn’t leaving. I have this:

[x_recent_posts count=“4” show_excerpt=“true” exclude_category="-2761, -1"]

// =============================================================================

// Recent Posts - Adding “exclude_category” to recent_posts shortcode
// ================================================================================

function x_shortcode_recent_posts2( $atts ) {
extract( shortcode_atts( array(
‘id’ => ‘’,
‘class’ => ‘’,
‘style’ => ‘’,
‘type’ => ‘’,
‘count’ => ‘’,
‘category’ => ‘’,
‘exclude_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 : '';
$exclude_category    = ( $exclude_category    != ''  ) ? $exclude_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}",
    'cat'              => "{$exclude_category}",
    "{$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>'
                     . '<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' );

});

Hey @fatcatgraphics,

Regretfully, we can’t provide a fix and further enhancements to sample codes provided here in our forum as they’re only meant to be a guide or help users get started with customization.

Further customization and maintenance of the custom codes should be shouldered by the user by learning how the code works or by hiring or consulting with a 3rd party developer.

If learning the code or hiring a developer isn’t an option, please use one of the bundled grid plugins instead. Both have the features you need. Please visit the links below for more details and plugin usage instructions.

Hope that helps and thank you for understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.