简体   繁体   中英

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 摘录

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM