Eng_Farghly
Eng_Farghly

Reputation: 2997

get and display excerpt posts in wordpress page

I try to add post excerpt in a page but not work I added in wordpress functions.php

add_post_type_support( 'page', 'excerpt' );

I enabled excerpt in this page excerpt post

this code that I write to get excerpt post

$recent_posts = wp_get_recent_posts('numberposts=5&order=DESC');
foreach( $recent_posts as $recent ):?>
   <h3>
     <a href="<?php echo get_permalink($recent["ID"]);?>">
    <?php echo $recent['post_title'];?>
    </a>
 </h3>
<p><?php                                    
   //  the_excerpt(); display post excerpt here
     ?></p>
<?php endforeach; ?>

Upvotes: 0

Views: 1592

Answers (1)

JDewitt
JDewitt

Reputation: 557

<?php
  $recent = new WP_Query( array(
    'posts_per_page' => 5,
    'order' => 'DESC',
  ) );

  if ( $recent->have_posts() ) : while ( $recent->have_posts() ) : $recent->the_post(); ?>

      <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></h3>

      <?php

      the_excerpt();

      endwhile;
    endif;
  wp_reset_postdata();
?>

Upvotes: 1

Related Questions