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

时间:2017-09-08 21:17:42

标签: php wordpress foreach

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

v.8

我在此页面中启用了摘录 excerpt post

我编写的这段代码摘录了

 <div id="rightWindow" style="background-image: url('Images/<?php echo $randomPic; ?>');"


  onclick="

    var enable = function() { counter++;

    if (counter > 7) {counter = 1;}

    $( '#rightWindow' ).css('background-image', 'url(Images/<?php

      echo $substring;

     ?>' + counter + '.jpg)');}

    enable();

    this.onclick = null;

    $( '#rightWindow' ).on('transitionend',
        function(e) {

        alert('ended!');

        this.onclick = enable;

      });


   "></div>

1 个答案:

答案 0 :(得分:1)

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