Note that there are some explanatory texts on larger screens.

plurals
  1. POLoop through sticky posts in wordpress?
    text
    copied!<p>I'm new to Wordpress and I'm trying to loop through sticky posts with this code:</p> <pre><code>&lt;?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' =&gt; $sticky, 'caller_get_posts' =&gt; 1 ) ); ?&gt; &lt;?php foreach ($stickies as $sticky) { the_title(); comments_number( 'Pas de commentaires', '1 commentaire', '% commentaires' ); } ?&gt; </code></pre> <p>However in the out put if I have 2 stickies posts, the first one is displayed two times...</p> <p>Any idea ?</p> <p>Thanks a lot for your help !</p> <p>EDIT :</p> <p>It seems that </p> <pre><code>foreach ($stickies['WP_Post Object'] as $sticky) { </code></pre> <p>get the good two articles, but I still have this error message : Warning: Invalid argument supplied for foreach()...</p> <p>Full code :</p> <pre><code> &lt;?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' =&gt; $sticky, 'caller_get_posts' =&gt; 1 ) ); ?&gt; &lt;?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' =&gt; "media-object img-rounded")); } the_title(); comments_number( 'Pas de commentaires', '1 commentaire', '% commentaires' ); } ?&gt; &lt;?php if (have_posts()) : ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;div class="media"&gt; &lt;a class="pull-left" href="&lt;?php the_permalink() ?&gt;"&gt; &lt;?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail('thumbnail', array('class' =&gt; "media-object img-rounded")); } ?&gt; &lt;/a&gt; &lt;div class="media-body"&gt; &lt;h3 class="media-heading"&gt;&lt;a class="permalink" href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title(); ?&gt;"&gt; &lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; Par &lt;?php the_author(); ?&gt;, le &lt;?php the_time('j F Y'); ?&gt; - &lt;?php comments_number( 'Pas de commentaires', '1 commentaire', '% commentaires' ); ?&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- /media --&gt; &lt;?php endwhile; ?&gt; &lt;?php endif; ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload