0

私はWordpressが初めてで、次のコードでスティッキー投稿をループしようとしています:

<?php
      /* Get all sticky posts */
      $sticky = get_option( 'sticky_posts' );

      /* Sort the stickies with the newest ones at the top */
      rsort( $sticky );


      /* Query sticky posts */
      $stickies = query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
      ?>

      <?php
       foreach ($stickies as $sticky) {

       the_title();
       comments_number( 'Pas de commentaires', '1 commentaire', '% commentaires' );


       }

      ?>

ただし、付箋の投稿が2つある場合、出力では最初の投稿が2回表示されます...

何か案が ?

助けてくれてありがとう!

編集 :

のようだ

foreach ($stickies['WP_Post Object'] as $sticky) { 

良い 2 つの記事を入手しますが、まだ次のエラー メッセージが表示されます: 警告: foreach() に無効な引数が指定されました...

完全なコード:

 <?php
  /* Get all sticky posts */
  $sticky = get_option( 'sticky_posts' );
  /* Sort the stickies with the newest ones at the top */
  rsort( $sticky );
  $stickies = query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
  ?>

  <?php
   foreach ($stickies['WP_Post Object'] as $sticky) {

   if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
     the_post_thumbnail('thumbnail', array('class'  => "media-object img-rounded"));
   } 
   the_title();
   comments_number( 'Pas de commentaires', '1 commentaire', '% commentaires' );


   }

  ?>

 <?php if (have_posts()) : ?>

  <?php while (have_posts()) : the_post(); ?>

  <div class="media">
    <a class="pull-left" href="<?php the_permalink() ?>">
    <?php 
    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
      the_post_thumbnail('thumbnail', array('class' => "media-object img-rounded"));
    } 
    ?>
    </a>
    <div class="media-body">
      <h3 class="media-heading"><a class="permalink" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h3>
      Par <?php the_author(); ?>, le <?php the_time('j F Y'); ?> - <?php comments_number( 'Pas de commentaires', '1 commentaire', '% commentaires' ); ?>
      <?php the_excerpt(); ?>
    </div>
  </div> <!-- /media -->



  <?php endwhile; ?>


  <?php endif; ?>
4

1 に答える 1