获取并显示wordpress页面中的摘录帖子

问题描述:

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

我尝试在页面中添加帖子摘录但不是我在wordpress functions.php中添加的工作 p> \ n

  add_post_type_support('page','excerpt'); 
  code>  pre> 
 
 

我在此页面中启用了摘录 p>

我编写此代码以获取摘录 p>

  $ recent_posts = wp_get_recent_posts('numberposts = 5&amp; order  = DESC'); 
foreach($ recent_posts as $ recent):?&gt; 
&lt; h3&gt; 
&lt; a href =“&lt;?php echo get_permalink($ recent [”ID“]);?&gt  ;“&gt; 
&lt;?php echo $ recent ['post_title'];?&gt; 
&lt; / a&gt; 
&lt; / h3&gt; 
&lt; p&gt;&lt;?php 
 // the_excerpt  (); 在这里显示帖子摘录
?&gt;&lt; / p&gt; 
&lt;?php endforeach;  ?&gt; 
  code>  pre> 
  div>

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