dqsp60748 2017-09-08 21:17
浏览 28
已采纳

获取并显示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; ?>
  • 写回答

1条回答 默认 最新

  • dougan7657 2017-09-08 21:56
    关注
    <?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();
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了
  • ¥15 微信小程序商城如何实现多商户收款 平台分润抽成